Good news: if you add 'keypress' => 'true' to the form element's #ajax array, 
Drupal takes care of this automatically.

On Jul 16, 2010, at 3:04 PM, Pierre Rineau wrote:

> 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.

Reply via email to