Form API and enter key press
Hi all! I experience a simple problem, which a lot of people must have experienced too. I have a lot of forms with multiple submit actions, my problem here is when a user press the enter key, it does submit the form, but using the first found action (in form API elements order). My problem here is because a multistep form ergonomic style would tell you to put <prev action> then <next action>, but when pressing enter, the <prev action> is the first submit button found so the browser will submit this one. I experience the same problem in other use case than multistep form. Is there a clean way (without too many JS) to force the default submit action on enter key press? Regards, -- Pierre (pounard) R. Courriel -- Jabber/XMPP(/GTalk): pounard@processus.org
Found my own solution, a jQuery based script that searchs for a specific class on form input elements and trick the browser by preprending a cloned version of the default submit button on top of the form. If works well, the page remains CSS/XHTML compliant, and is, I think, cross browser compatible. Do you people think it worth the shot commiting this really simple module on drupal.org cvs and create a new project ? The fact is I need it on many modules, which are not dependent by the way, so I need this to be in its own projet. Any people interested? -- Pierre Rineau Courriel -- Jabber/XMPP(/GTalk): pierre.rineau@processus.org Tél: +33 (0)6 59 46 62 27
I'm interested, if you could solve this generically. It's annoyed me forever - especially on the admin/settings/performance page where I was always clearing the cache instead of saving my settings. This is browser-dependent behavior. Firefox behaves differently from Chrome. I believe Chrome just won't act if there's more than one button. Firefox takes the first. I'm definitely interested in a general solution. -Randy On Wed, Mar 3, 2010 at 4:01 AM, Pierre Rineau. < pierre.rineau@makina-corpus.com> wrote:
Found my own solution, a jQuery based script that searchs for a specific class on form input elements and trick the browser by preprending a cloned version of the default submit button on top of the form.
If works well, the page remains CSS/XHTML compliant, and is, I think, cross browser compatible.
Do you people think it worth the shot commiting this really simple module on drupal.org cvs and create a new project ?
The fact is I need it on many modules, which are not dependent by the way, so I need this to be in its own projet.
Any people interested?
-- Pierre Rineau Courriel -- Jabber/XMPP(/GTalk): pierre.rineau@processus.org Tél: +33 (0)6 59 46 62 27
-- Randy Fay Drupal Development, troubleshooting, and debugging randy@randyfay.com +1 970.462.7450
Why not put your jQuery plugin on the jQuery plugin's page? Seems only natural ;) On Wed, Mar 3, 2010 at 8:13 AM, Randy Fay <randy@randyfay.com> wrote:
I'm interested, if you could solve this generically. It's annoyed me forever - especially on the admin/settings/performance page where I was always clearing the cache instead of saving my settings.
This is browser-dependent behavior. Firefox behaves differently from Chrome. I believe Chrome just won't act if there's more than one button. Firefox takes the first.
I'm definitely interested in a general solution.
-Randy
On Wed, Mar 3, 2010 at 4:01 AM, Pierre Rineau. < pierre.rineau@makina-corpus.com> wrote:
Found my own solution, a jQuery based script that searchs for a specific class on form input elements and trick the browser by preprending a cloned version of the default submit button on top of the form.
If works well, the page remains CSS/XHTML compliant, and is, I think, cross browser compatible.
Do you people think it worth the shot commiting this really simple module on drupal.org cvs and create a new project ?
The fact is I need it on many modules, which are not dependent by the way, so I need this to be in its own projet.
Any people interested?
-- Pierre Rineau Courriel -- Jabber/XMPP(/GTalk): pierre.rineau@processus.org Tél: +33 (0)6 59 46 62 27
-- Randy Fay Drupal Development, troubleshooting, and debugging randy@randyfay.com +1 970.462.7450
On 2010-03-03, at 6:01 AM, Pierre Rineau. wrote:
Found my own solution, a jQuery based script that searchs for a specific class on form input elements and trick the browser by preprending a cloned version of the default submit button on top of the form.
When I've dealt with this in the past, I've caught the input event and fired the appropriate action. How does that compare to your solution? --Andrew
On Wed, 2010-03-03 at 14:55 -0500, Andrew Berry wrote:
On 2010-03-03, at 6:01 AM, Pierre Rineau. wrote:
Found my own solution, a jQuery based script that searchs for a specific class on form input elements and trick the browser by preprending a cloned version of the default submit button on top of the form.
When I've dealt with this in the past, I've caught the input event and fired the appropriate action. How does that compare to your solution?
--Andrew
I read some posts saying that catching the enter key can be hard to do with some browsers. I finally choose another solution: copying the default button DOM element on top of the form, but hidden in order to be fully transparent for the end user. It seemed to be the nicest solution because it does not requires your javascript to add any events on buttons and it let the browser do its job. See http://drupal.org/project/default_submit Regards, Pierre.
Does this work with Chrome? It seems like I've seen Chrome refuse to use the enter key when there is more than one submit on the page. -Randy On Mon, Mar 8, 2010 at 1:55 AM, Pierre Rineau. < pierre.rineau@makina-corpus.com> wrote:
On Wed, 2010-03-03 at 14:55 -0500, Andrew Berry wrote:
On 2010-03-03, at 6:01 AM, Pierre Rineau. wrote:
Found my own solution, a jQuery based script that searchs for a specific class on form input elements and trick the browser by preprending a cloned version of the default submit button on top of the form.
When I've dealt with this in the past, I've caught the input event and fired the appropriate action. How does that compare to your solution?
--Andrew
I read some posts saying that catching the enter key can be hard to do with some browsers. I finally choose another solution: copying the default button DOM element on top of the form, but hidden in order to be fully transparent for the end user. It seemed to be the nicest solution because it does not requires your javascript to add any events on buttons and it let the browser do its job.
See http://drupal.org/project/default_submit
Regards, Pierre.
-- Randy Fay Drupal Development, troubleshooting, and debugging randy@randyfay.com +1 970.462.7450
On Mon, 2010-03-08 at 09:06 -0700, Randy Fay wrote:
Does this work with Chrome? It seems like I've seen Chrome refuse to use the enter key when there is more than one submit on the page.
-Randy
If so, then Chrome is evil :) It needs testing/improvement and any ideas are welcome. Pierre.
On Mon, Mar 8, 2010 at 12:12 PM, Pierre Rineau. <pierre.rineau@makina-corpus.com> wrote:
On Mon, 2010-03-08 at 09:06 -0700, Randy Fay wrote:
Does this work with Chrome? It seems like I've seen Chrome refuse to use the enter key when there is more than one submit on the page.
-Randy
If so, then Chrome is evil :) It needs testing/improvement and any ideas are welcome.
I used to think it was pretty annoying that WebKit based browsers didn't submit on enter. After using Chrome for a bit and no longer having problems with things like Views filters inadvertently becoming exposed I think it's the correct decision. andrew
On Mon, 2010-03-08 at 14:30 -0500, andrew morton wrote:
I used to think it was pretty annoying that WebKit based browsers didn't submit on enter. After using Chrome for a bit and no longer having problems with things like Views filters inadvertently becoming exposed I think it's the correct decision.
andrew
Maybe you're right, but whoever is right, I never, never use keyboard shortcuts on a such complex UI than Views UI, too dangerous. So if you're right, to ensure the enter key behavior on all browsers catching the key event seems to be the only one solution that can really works. My first idea was to force the browser to submit the right button when it submits the form using the enter key to ensure that end user won't be surprised. But it wasn't about forcing the enter key press event to submit, this is two different statements. Any idea's still welcome. Pierre.
participants (5)
-
Andrew Berry -
andrew morton -
Cameron Eagans -
Pierre Rineau. -
Randy Fay