Hi - I have the following problem: my app has a form that acts as a
filter to a table on the page, so that the user can search any value in
the table (via text box) or use select lists for more specific search.
The form is being observed by an observe_form helper that runs every 1-2
seconds or so. It's all still in testing.
I noticed that when I hit return while in the textbox, the form posts
and redirects me to an action unknown page. I want to remove that
functionality so that hitting enter wont do anything -- any idea how to
do it?
I believe if you put a textarea in your form, the browser will not submit the form if you hit the enter key. It depends on which browser you are using though.
Create a form without a submit tag. Put in another control on the
web page that does $('id_of_my_form').submit(); using a javascript
onclick event or whatever.
You can add Javascript to check for the value of the key pressed and
ignore it if it is the Enter key. I had to do the exact same thing for
the Backspace key not long ago, which was working as the Back icon in
some instances.
I have a sample but not here. I could give it to you if you still need
it tonight when I get home.
form_for results in a POST operation. You are checking for
request.xhr? in your controller to render the partial. Use
remote_form_for instead to get a XHR request.
Pressing an enter key in a text field doesn't submit a form. The tags
don't add that in.
form_for results in a POST operation. You are checking for
request.xhr? in your controller to render the partial. Use
remote_form_for instead to get a XHR request.
Pressing an enter key in a text field doesn't submit a form. The tags
don't add that in.
Regards,
Mukund
I changed the form_for to remote_form_for, and this disabled the search
for the new view - Thanks. Using firebug I still see it's getting a 404
error when I hit enter in the text field. so I'm not sure what's
submitting the form on enter..
Also, I'm afraid I'm not sure what you mean with the XHR part - should I
just change
render :partial => 'person' if request.xml_http_request?
to
render :partial => 'person'
now that remote_form_for submits an ajax request?