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.