[development] Submit via AJAX by pressing Enter

Pierre Rineau pierre.rineau at makina-corpus.com
Fri Jul 16 19:04:22 UTC 2010


Le vendredi 16 juillet 2010 à 08:21 -0400, Darren Oh a écrit :
> Does Drupal 7 provide a way to AJAX-submit a form when the Enter key is pressed in a text field? I tried using "submit" as the event in the #ajax array, but that didn't prevent a page reload.

There is no easy way to capture enter key event, you will need
javascript code.

You can see this module http://drupal.org/project/default_submit (I did
it, by I do not advice you to use it!) which implements one way to do it
(not the better).

Most browsers will use the first submit or button in the current focused
form when the user click enters, but a lot of others will just do
nothing.

JavaScript is the key!

Pierre.



More information about the development mailing list