Ruby on Rails Thursday, December 30, 2010

I need to do some JS processing in the client before contacting the
server (fwiw, this is for Google geocoding). The JS does its processing
and concocts a form to send back to the server. The latter part is
working fine.

In a previous iteration, I had the following. It activated the JS code
on any change to the text field, and worked (although now I know I
should use a text_field_tag rather than abusing a text_field):

<!-- a named field for the authenticity_token so initialize() can find
it. -->
<input type="hidden" id="authenticity_token" value="<%=
form_authenticity_token %>"\>
<!-- a field for the user to submit a raw address for geocoding -->
<div class="raw_address">
Type an address: <%= text_field :raw, :address, :onchange =>
"geocodeAddress()" %>
</div>

But now now that I've added another field, my instinct says to create a
form with a submit button. But I don't see how to create a form that
does NOT submit HTML when the submit button is pushed. Here's the
errant form. What I want is the "search" button to call
geocodeAddress() and nothing more.

<%= form_tag(premises_path, :remote => true) do %>
<%= hidden_field_tag("authenticity_token", form_authenticity_token,
:id => "authenticity_token") %>
<%= label_tag("address", "Type an address:") %>
<%= text_field_tag("raw_address", nil, :size => 96, :id =>
"raw_address") %>
<%= label_tag("occupants", "Occupants:") %>
<%= select_tag("occupants", options_for_select([0.5, ..., 8.0], 2.0))
%>
<%= submit_tag("search", :onchange => "geocodeAddress()") %>
<% end %>

Suggestions? (Perhaps I could just lose the form altogether...)

- ff

P.S.: Marnen, I know what you're thinking! :) I'll reframe it as UJS
once I get the basics working.

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment