Greetings! If a user presses the ENTER key while in a form, the form''s submitted. Is there a standard approach / way to trap that so that, for example, the form would only be submitted by a mouse click on the submit button? TIA, Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I should have said "a standard Rails approach". ----- Original Message ----- From: Bill Walton To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Sent: Tuesday, September 02, 2008 2:01 PM Subject: [Rails] How can I prevent ENTER from submitting form? Greetings! If a user presses the ENTER key while in a form, the form''s submitted. Is there a standard approach / way to trap that so that, for example, the form would only be submitted by a mouse click on the submit button? TIA, Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Tue, Sep 2, 2008 at 3:06 PM, Bill Walton <bill.walton-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote:> > I should have said "a standard Rails approach". > > ----- Original Message ----- > From: Bill Walton > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > Sent: Tuesday, September 02, 2008 2:01 PM > Subject: [Rails] How can I prevent ENTER from submitting form? > > > Greetings! > > If a user presses the ENTER key while in a form, the form''s submitted. Is > there a standard approach / way to trap that so that, for example, the form > would only be submitted by a mouse click on the submit button? > > TIA, > Bill > > >Must say this is an odd request. It drives me absolutely nuts when enter does NOT submit the form and I''m forced to reach for my mouse. That said, it''s simple: don''t add a submit button (input type="submit"). Use a link that uses javascript to submit the form. Jason --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
For the button, do not use type="submit" attribute, instead use type="button", and a on click handler. So, your button markup will look something like below <input type="button" name="mybutton" value="Submit" onclick="document.forms[0].submit()"/> On Sep 3, 12:06 am, "Bill Walton" <bill.wal...-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote:> I should have said "a standard Rails approach". > > > > ----- Original Message ----- > From: Bill Walton > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > Sent: Tuesday, September 02, 2008 2:01 PM > Subject: [Rails] How can I prevent ENTER from submitting form? > > Greetings! > > If a user presses the ENTER key while in a form, the form''s submitted. Is > there a standard approach / way to trap that so that, for example, the form > would only be submitted by a mouse click on the submit button? > > TIA, > Bill- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I''m just thinking that a single line form will submit on the Enter button, even if there is no submit button, if this is the case and you don''t want to submit the form at all you could add some javascript like this (assuming you are including prototype) : $(''id-of-form'').observe(''submit'', function(e) { e.stop(); }.bindAsEventListener(this)); // Untested alternatively, if you still want the form to be submitted if/when a submit button is pressed maybe something like: $(''id-of-form'').observe(''submit'', function(e) { e.keyCode == Event.KEY_ENTER ? e.stop() : null; }.bindAsEventListener(this)); // Untested Simon On Sep 2, 8:54 pm, Srikanth <sri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> For the button, do not use type="submit" attribute, instead use > type="button", and a on click handler. So, your button markup will > look something like below > <input type="button" name="mybutton" value="Submit" > onclick="document.forms[0].submit()"/> > > On Sep 3, 12:06 am, "Bill Walton" <bill.wal...-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote: > > > I should have said "a standard Rails approach". > > > ----- Original Message ----- > > From: Bill Walton > > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > Sent: Tuesday, September 02, 2008 2:01 PM > > Subject: [Rails] How can I prevent ENTER from submitting form? > > > Greetings! > > > If a user presses the ENTER key while in a form, the form''s submitted. Is > > there a standard approach / way to trap that so that, for example, the form > > would only be submitted by a mouse click on the submit button? > > > TIA, > > Bill- Hide quoted text - > > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
for the record... the type of submit button isn''t going to change this behavior. the _presence_ of a submit button doesn''t even change it. outside of using js (to either trap keys or return false or whatever approach you''d use), i don''t think you can do it. but you''d have to be catching the return and perhaps comparing "this" to verify which element is sending the "click". not sure how much you wanted a purely-js solution so i''m not spending lots of cycles processing it. ;) but it definitely could be done with js. hth RSL On Tue, Sep 2, 2008 at 3:54 PM, Srikanth <srikps-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > For the button, do not use type="submit" attribute, instead use > type="button", and a on click handler. So, your button markup will > look something like below > <input type="button" name="mybutton" value="Submit" > onclick="document.forms[0].submit()"/> > > On Sep 3, 12:06 am, "Bill Walton" <bill.wal...-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote: >> I should have said "a standard Rails approach". >> >> >> >> ----- Original Message ----- >> From: Bill Walton >> To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >> Sent: Tuesday, September 02, 2008 2:01 PM >> Subject: [Rails] How can I prevent ENTER from submitting form? >> >> Greetings! >> >> If a user presses the ENTER key while in a form, the form''s submitted. Is >> there a standard approach / way to trap that so that, for example, the form >> would only be submitted by a mouse click on the submit button? >> >> TIA, >> Bill- Hide quoted text - >> >> - Show quoted text - > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
attaching a little html for anyone who wants to verify my claim that a button-less form can still submit from hitting enter inside a form input [text]. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Submittable Buttonless Form</title> </head> <body> <form action="foo"> <p> <input type="text"> </p> </form> </body> </html> RSL On Wed, Sep 3, 2008 at 8:15 AM, Russell Norris <rsl-ftMzyaTR+bHNyFkoKTPOtdi2O/JbrIOy@public.gmane.org> wrote:> for the record... the type of submit button isn''t going to change this > behavior. the _presence_ of a submit button doesn''t even change it. > outside of using js (to either trap keys or return false or whatever > approach you''d use), i don''t think you can do it. but you''d have to be > catching the return and perhaps comparing "this" to verify which > element is sending the "click". not sure how much you wanted a > purely-js solution so i''m not spending lots of cycles processing it. > ;) but it definitely could be done with js. hth > > RSL > > On Tue, Sep 2, 2008 at 3:54 PM, Srikanth <srikps-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> For the button, do not use type="submit" attribute, instead use >> type="button", and a on click handler. So, your button markup will >> look something like below >> <input type="button" name="mybutton" value="Submit" >> onclick="document.forms[0].submit()"/> >> >> On Sep 3, 12:06 am, "Bill Walton" <bill.wal...-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote: >>> I should have said "a standard Rails approach". >>> >>> >>> >>> ----- Original Message ----- >>> From: Bill Walton >>> To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >>> Sent: Tuesday, September 02, 2008 2:01 PM >>> Subject: [Rails] How can I prevent ENTER from submitting form? >>> >>> Greetings! >>> >>> If a user presses the ENTER key while in a form, the form''s submitted. Is >>> there a standard approach / way to trap that so that, for example, the form >>> would only be submitted by a mouse click on the submit button? >>> >>> TIA, >>> Bill- Hide quoted text - >>> >>> - Show quoted text - >> >> >> >> >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
And as a counter point, I present this form, which does *not* submit on enter <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Submittable Buttonless Form</title> </head> <body> <form action="foo" method="post"> <div> <input type="text" id="login" name="login"/> </div> <div> <input type="password" name="password" name="login"/> </div> </form> </body> </html> And this one, that does <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Submittable Buttonless Form</title> </head> <body> <form action="foo" method="post"> <div> <input type="text" id="login" name="login"/> </div> <div> <input type="password" name="password" name="login"/> </div> <div> <input type="submit"/> </div> </form> </body> </html> So yeah, there''s a combination of form fields that will not submit on Enter. Sometimes it will work, sometimes it won''t. If you want it to work all the time, put in a submit tag. If you don''t want it to happen ever, you probably need extra javascript just to be safe. Jason On Wed, Sep 3, 2008 at 8:20 AM, Russell Norris <rsl-ftMzyaTR+bHNyFkoKTPOtdi2O/JbrIOy@public.gmane.org> wrote:> > attaching a little html for anyone who wants to verify my claim that a > button-less form can still submit from hitting enter inside a form > input [text]. > > > <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" > "http://www.w3.org/TR/html4/strict.dtd"> > <html> > <head> > <title>Submittable Buttonless Form</title> > </head> > <body> > <form action="foo"> > <p> > <input type="text"> > </p> > </form> > </body> > </html> > > > RSL > > On Wed, Sep 3, 2008 at 8:15 AM, Russell Norris <rsl-ftMzyaTR+bHNyFkoKTPOtdi2O/JbrIOy@public.gmane.org> wrote: >> for the record... the type of submit button isn''t going to change this >> behavior. the _presence_ of a submit button doesn''t even change it. >> outside of using js (to either trap keys or return false or whatever >> approach you''d use), i don''t think you can do it. but you''d have to be >> catching the return and perhaps comparing "this" to verify which >> element is sending the "click". not sure how much you wanted a >> purely-js solution so i''m not spending lots of cycles processing it. >> ;) but it definitely could be done with js. hth >> >> RSL >> >> On Tue, Sep 2, 2008 at 3:54 PM, Srikanth <srikps-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>> For the button, do not use type="submit" attribute, instead use >>> type="button", and a on click handler. So, your button markup will >>> look something like below >>> <input type="button" name="mybutton" value="Submit" >>> onclick="document.forms[0].submit()"/> >>> >>> On Sep 3, 12:06 am, "Bill Walton" <bill.wal...-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote: >>>> I should have said "a standard Rails approach". >>>> >>>> >>>> >>>> ----- Original Message ----- >>>> From: Bill Walton >>>> To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >>>> Sent: Tuesday, September 02, 2008 2:01 PM >>>> Subject: [Rails] How can I prevent ENTER from submitting form? >>>> >>>> Greetings! >>>> >>>> If a user presses the ENTER key while in a form, the form''s submitted. Is >>>> there a standard approach / way to trap that so that, for example, the form >>>> would only be submitted by a mouse click on the submit button? >>>> >>>> TIA, >>>> Bill- Hide quoted text - >>>> >>>> - Show quoted text - >>> >>> >> >>> >> > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bah, I did accidentally name both elements the same thing, however, having them named right (name="password") doesn''t change anything, the form still doesn''t submit on enter. Jason On Wed, Sep 3, 2008 at 9:34 AM, Jason Roelofs <jameskilton-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> And as a counter point, I present this form, which does *not* submit on enter > > <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" > "http://www.w3.org/TR/html4/strict.dtd"> > <html> > <head> > <title>Submittable Buttonless Form</title> > </head> > <body> > <form action="foo" method="post"> > <div> > <input type="text" id="login" name="login"/> > </div> > > <div> > <input type="password" name="password" name="login"/> > </div> > </form> > </body> > </html> > > And this one, that does > > <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" > "http://www.w3.org/TR/html4/strict.dtd"> > <html> > <head> > <title>Submittable Buttonless Form</title> > </head> > <body> > <form action="foo" method="post"> > <div> > <input type="text" id="login" name="login"/> > </div> > > <div> > <input type="password" name="password" name="login"/> > </div> > > <div> > <input type="submit"/> > </div> > </form> > </body> > </html> > > So yeah, there''s a combination of form fields that will not submit on > Enter. Sometimes it will work, sometimes it won''t. If you want it to > work all the time, put in a submit tag. If you don''t want it to happen > ever, you probably need extra javascript just to be safe. > > Jason > > On Wed, Sep 3, 2008 at 8:20 AM, Russell Norris <rsl-ftMzyaTR+bHNyFkoKTPOtdi2O/JbrIOy@public.gmane.org> wrote: >> >> attaching a little html for anyone who wants to verify my claim that a >> button-less form can still submit from hitting enter inside a form >> input [text]. >> >> >> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" >> "http://www.w3.org/TR/html4/strict.dtd"> >> <html> >> <head> >> <title>Submittable Buttonless Form</title> >> </head> >> <body> >> <form action="foo"> >> <p> >> <input type="text"> >> </p> >> </form> >> </body> >> </html> >> >> >> RSL >> >> On Wed, Sep 3, 2008 at 8:15 AM, Russell Norris <rsl-ftMzyaTR+bHNyFkoKTPOtdi2O/JbrIOy@public.gmane.org> wrote: >>> for the record... the type of submit button isn''t going to change this >>> behavior. the _presence_ of a submit button doesn''t even change it. >>> outside of using js (to either trap keys or return false or whatever >>> approach you''d use), i don''t think you can do it. but you''d have to be >>> catching the return and perhaps comparing "this" to verify which >>> element is sending the "click". not sure how much you wanted a >>> purely-js solution so i''m not spending lots of cycles processing it. >>> ;) but it definitely could be done with js. hth >>> >>> RSL >>> >>> On Tue, Sep 2, 2008 at 3:54 PM, Srikanth <srikps-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>> >>>> For the button, do not use type="submit" attribute, instead use >>>> type="button", and a on click handler. So, your button markup will >>>> look something like below >>>> <input type="button" name="mybutton" value="Submit" >>>> onclick="document.forms[0].submit()"/> >>>> >>>> On Sep 3, 12:06 am, "Bill Walton" <bill.wal...-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote: >>>>> I should have said "a standard Rails approach". >>>>> >>>>> >>>>> >>>>> ----- Original Message ----- >>>>> From: Bill Walton >>>>> To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >>>>> Sent: Tuesday, September 02, 2008 2:01 PM >>>>> Subject: [Rails] How can I prevent ENTER from submitting form? >>>>> >>>>> Greetings! >>>>> >>>>> If a user presses the ENTER key while in a form, the form''s submitted. Is >>>>> there a standard approach / way to trap that so that, for example, the form >>>>> would only be submitted by a mouse click on the submit button? >>>>> >>>>> TIA, >>>>> Bill- Hide quoted text - >>>>> >>>>> - Show quoted text - >>>> >>>> >> >>>> >>> >> >> >> >> >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
what the heck. that is weird. is it perhaps the method="post"? what''s going on here where you and i can make really similar HTML that reacts completely differently? curiouser and curiouser. ;) RSL On Wed, Sep 3, 2008 at 9:39 AM, Jason Roelofs <jameskilton-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Bah, I did accidentally name both elements the same thing, however, > having them named right (name="password") doesn''t change anything, the > form still doesn''t submit on enter. > > Jason > > On Wed, Sep 3, 2008 at 9:34 AM, Jason Roelofs <jameskilton-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> And as a counter point, I present this form, which does *not* submit on enter >> >> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" >> "http://www.w3.org/TR/html4/strict.dtd"> >> <html> >> <head> >> <title>Submittable Buttonless Form</title> >> </head> >> <body> >> <form action="foo" method="post"> >> <div> >> <input type="text" id="login" name="login"/> >> </div> >> >> <div> >> <input type="password" name="password" name="login"/> >> </div> >> </form> >> </body> >> </html> >> >> And this one, that does >> >> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" >> "http://www.w3.org/TR/html4/strict.dtd"> >> <html> >> <head> >> <title>Submittable Buttonless Form</title> >> </head> >> <body> >> <form action="foo" method="post"> >> <div> >> <input type="text" id="login" name="login"/> >> </div> >> >> <div> >> <input type="password" name="password" name="login"/> >> </div> >> >> <div> >> <input type="submit"/> >> </div> >> </form> >> </body> >> </html> >> >> So yeah, there''s a combination of form fields that will not submit on >> Enter. Sometimes it will work, sometimes it won''t. If you want it to >> work all the time, put in a submit tag. If you don''t want it to happen >> ever, you probably need extra javascript just to be safe. >> >> Jason >> >> On Wed, Sep 3, 2008 at 8:20 AM, Russell Norris <rsl-ftMzyaTR+bHNyFkoKTPOtdi2O/JbrIOy@public.gmane.org> wrote: >>> >>> attaching a little html for anyone who wants to verify my claim that a >>> button-less form can still submit from hitting enter inside a form >>> input [text]. >>> >>> >>> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" >>> "http://www.w3.org/TR/html4/strict.dtd"> >>> <html> >>> <head> >>> <title>Submittable Buttonless Form</title> >>> </head> >>> <body> >>> <form action="foo"> >>> <p> >>> <input type="text"> >>> </p> >>> </form> >>> </body> >>> </html> >>> >>> >>> RSL >>> >>> On Wed, Sep 3, 2008 at 8:15 AM, Russell Norris <rsl-ftMzyaTR+bHNyFkoKTPOtdi2O/JbrIOy@public.gmane.org> wrote: >>>> for the record... the type of submit button isn''t going to change this >>>> behavior. the _presence_ of a submit button doesn''t even change it. >>>> outside of using js (to either trap keys or return false or whatever >>>> approach you''d use), i don''t think you can do it. but you''d have to be >>>> catching the return and perhaps comparing "this" to verify which >>>> element is sending the "click". not sure how much you wanted a >>>> purely-js solution so i''m not spending lots of cycles processing it. >>>> ;) but it definitely could be done with js. hth >>>> >>>> RSL >>>> >>>> On Tue, Sep 2, 2008 at 3:54 PM, Srikanth <srikps-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>> >>>>> For the button, do not use type="submit" attribute, instead use >>>>> type="button", and a on click handler. So, your button markup will >>>>> look something like below >>>>> <input type="button" name="mybutton" value="Submit" >>>>> onclick="document.forms[0].submit()"/> >>>>> >>>>> On Sep 3, 12:06 am, "Bill Walton" <bill.wal...-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote: >>>>>> I should have said "a standard Rails approach". >>>>>> >>>>>> >>>>>> >>>>>> ----- Original Message ----- >>>>>> From: Bill Walton >>>>>> To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >>>>>> Sent: Tuesday, September 02, 2008 2:01 PM >>>>>> Subject: [Rails] How can I prevent ENTER from submitting form? >>>>>> >>>>>> Greetings! >>>>>> >>>>>> If a user presses the ENTER key while in a form, the form''s submitted. Is >>>>>> there a standard approach / way to trap that so that, for example, the form >>>>>> would only be submitted by a mouse click on the submit button? >>>>>> >>>>>> TIA, >>>>>> Bill- Hide quoted text - >>>>>> >>>>>> - Show quoted text - >>>>> >>>>> >> >>>>> >>>> >>> >>> >> >>> >> > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Set up an onsubmit handler for the form that returns false unless some value is true. Configure the submit button to set that value to true and then submit the form. -philip On Sep 3, 2008, at 5:15 AM, Russell Norris wrote:> > for the record... the type of submit button isn''t going to change this > behavior. the _presence_ of a submit button doesn''t even change it. > outside of using js (to either trap keys or return false or whatever > approach you''d use), i don''t think you can do it. but you''d have to be > catching the return and perhaps comparing "this" to verify which > element is sending the "click". not sure how much you wanted a > purely-js solution so i''m not spending lots of cycles processing it. > ;) but it definitely could be done with js. hth > > RSL > > On Tue, Sep 2, 2008 at 3:54 PM, Srikanth <srikps-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> For the button, do not use type="submit" attribute, instead use >> type="button", and a on click handler. So, your button markup will >> look something like below >> <input type="button" name="mybutton" value="Submit" >> onclick="document.forms[0].submit()"/> >> >> On Sep 3, 12:06 am, "Bill Walton" <bill.wal...-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote: >>> I should have said "a standard Rails approach". >>> >>> >>> >>> ----- Original Message ----- >>> From: Bill Walton >>> To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >>> Sent: Tuesday, September 02, 2008 2:01 PM >>> Subject: [Rails] How can I prevent ENTER from submitting form? >>> >>> Greetings! >>> >>> If a user presses the ENTER key while in a form, the form''s >>> submitted. Is >>> there a standard approach / way to trap that so that, for example, >>> the form >>> would only be submitted by a mouse click on the submit button? >>> >>> TIA, >>> Bill- Hide quoted text - >>> >>> - Show quoted text - >> >>> >> > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ok ok, stop.. just stop... you''re all making it too complicated. [shakes head] Let''s go over things... You want a button that submits normally but want to try and stop the enter key submitting it. To do this, you''re going to need to understand the relationship between the ENTER key, the Mousebutton and Javascript. When you press ENTER in a form, the form automatically goes to the first Submit button it can find (or usually the closest in accordance to tabindexing) and then submits the form. It treats the ENTER key like it was the left mouse button because it has to assume that some people don''t have a mouse (partially sighted, screen readers etc). In Javascript, when you press ENTER in a form, it also relates this to the left mouse button being clicked, which therefor activates the "onclick" event. It also sets a keycode (13) so it knows what key on the keyboard was pressed. However, Javascript has another event called "onmousedown" which only works if the mouse button is pressed down. It doesn''t get related to the keyboard or the ENTER key. I believe onkeydown is for that. Now!, the onmousedown event is activated before the onclick method which means we have a way of setting a rule before doing anything with onclick. (Onclick doesn''t activate until you let go of the clicked button). So, the easiest solution (if we don''t do anything fancy with functions) is to apply two javascript events to your submit button. Example =============<input type="submit" name="mybutton" onmousedown="this.title=1" onclick="if(this.title!=1){return false;}" value="Submit my Form" /> How it works? =============What happens is.. if you click the button, the onmousedown event runs first which renames/sets the title of the button. When you let go of the mousebutton, the onclick takes effect and checks the title to see if its set to 1. If it is, then it submits, otherwise it returns false. This means that, if you pressed ENTER, onmousedown wouldn''t have renamed the title which means the onclick will return false and not submit the form. Obviously, as I know the Mootools library I''ve made a transparent method which just adds the two events to all input=submit buttons on the page. The inline example here is just to show you the method for copying and pasting quickly :) Hope that helps someone! Adam www.greatbigmassive.net -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The simplest way is pass this code to your form :D <input type="text" style="display:none"> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Easy and clean, thanks you -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Jordon Bedwell
2012-Nov-15 16:59 UTC
Re: Re: How can I prevent ENTER from submitting form?
On Thu, Nov 15, 2012 at 10:23 AM, Albert Català <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Easy and clean, thanks youIf you want/need to prevent "enter" from submitting a form, you are doing it wrong and you could be be alienating some disabled people who do not use a mouse and rely on their keyboard. I know even if that''s not the case, if I ran into a site that prevented me from pressing enter to submit a form (because I am still a tab, tab, enter person) I would walk away from that site and probably blacklist it in my personal DNS. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Jordon Bedwell wrote in post #1084597:> On Thu, Nov 15, 2012 at 10:23 AM, Albert Catal <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: >> Easy and clean, thanks you > > If you want/need to prevent "enter" from submitting a form, you are > doing it wrong and you could be be alienating some disabled people who > do not use a mouse and rely on their keyboard. I know even if that''s > not the case, if I ran into a site that prevented me from pressing > enter to submit a form (because I am still a tab, tab, enter person) I > would walk away from that site and probably blacklist it in my > personal DNS.Hello, My problem is than I''m doing a excel style form, and some fields have remote calls (onchange) to calculate another fields. And the form has a submit button, so I user press enter the remote call (ajax call) is not finished (some times not initiated) when the form is submited and saved with bad calculated values. To solve it, I have to do two things: 1 - Prevent enter key (this forum issue) 2 - And,despite this, user can click on submit button faster than field onchange function is finished. This second issue i still don''t know how to solve it What do you tink? Do you hace the pont 2 answer? thanks a lot and sorry for my bad english Albert -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Nov 15, 2012, at 12:26 PM, Albert Català wrote:> Jordon Bedwell wrote in post #1084597: >> On Thu, Nov 15, 2012 at 10:23 AM, Albert Catal <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> >> wrote: >>> Easy and clean, thanks you >> >> If you want/need to prevent "enter" from submitting a form, you are >> doing it wrong and you could be be alienating some disabled people who >> do not use a mouse and rely on their keyboard. I know even if that''s >> not the case, if I ran into a site that prevented me from pressing >> enter to submit a form (because I am still a tab, tab, enter person) I >> would walk away from that site and probably blacklist it in my >> personal DNS. > > Hello, My problem is than I''m doing a excel style form, and some fields > have remote calls (onchange) to calculate another fields. And the form > has a submit button, so I user press enter the remote call (ajax call) > is not finished (some times not initiated) when the form is submited and > saved with bad calculated values. > To solve it, I have to do two things: > 1 - Prevent enter key (this forum issue) > 2 - And,despite this, user can click on submit button faster than field > onchange function is finished. This second issue i still don''t know how > to solve it > > What do you tink? > Do you hace the pont 2 answer? > > thanks a lot and sorry for my bad englishYour English is guaranteed 100% better than my attempt at your native language, unless that''s Latin (didn''t think it was). What you need to do is use callback functions in your processing JavaScript to disable the submit button while they''re running, and enable them when they''re done. That way if you have blocked the enter key, the only way the form will be submitted is with a click on an enabled form button. Here''s a quick mockup (I don''t know what your existing cell calculation code looks like). //stop all submits from the form $$(''form'').invoke(''observe'', ''submit'', function(evt){ evt.stop(); }); //let a click on <input type="submit" id="real_submit" /> send the form $(''real_submit'').observe(''click'', function(evt){ this.form.submit(); }); //fake spreadsheet code for demo purposes $$(''input[type="text"]'').invoke(''observe'', ''blur'', function(evt){ var elm = evt.element(); var submits = elm.select(''input[type="submit"]''); new Ajax.Request(''/some/endpoint'', { parameters: {id: elm.id, value: $F(elm)}, onCreate: function(){ submits.invoke(''disable''); }, //can''t be clicked onSuccess: function(transport){ submits.invoke(''enable''); //can be clicked $(''total'').update(transport.responseText); } }); }); That''s all written with Prototype.js methods, but you could do similar in any JavaScript you like. Walter -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
I don''t know my english but my javascript is very newbie, too much newbie ¿ Is not this, the same or similar, that disable the sumbmit button at the begining of onchange event and activate it at the end?...something like: <%= f.text_field :amount, onchange=>"disable_submit();" + remote_function(...my caculations) +"enable_submit();" ) %></p> where enable_submit() and disbale_submit() just does what says, activate and deactivate the submit button isn''t it? Thanks, Albert -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Thanks for that Adam, helped me a lot. On Saturday, January 10, 2009 1:10:15 AM UTC+10, Adam Massive wrote:> > Ok ok, stop.. just stop... you''re all making it too complicated. > [shakes head] > > > Let''s go over things... > You want a button that submits normally but want to try and stop the > enter key submitting it. To do this, you''re going to need to understand > the relationship between the ENTER key, the Mousebutton and Javascript. > > When you press ENTER in a form, the form automatically goes to the first > Submit button it can find (or usually the closest in accordance to > tabindexing) and then submits the form. It treats the ENTER key like it > was the left mouse button because it has to assume that some people > don''t have a mouse (partially sighted, screen readers etc). > > In Javascript, when you press ENTER in a form, it also relates this to > the left mouse button being clicked, which therefor activates the > "onclick" event. It also sets a keycode (13) so it knows what key on the > keyboard was pressed. > > However, Javascript has another event called "onmousedown" which only > works if the mouse button is pressed down. It doesn''t get related to the > keyboard or the ENTER key. I believe onkeydown is for that. > > Now!, the onmousedown event is activated before the onclick method which > means we have a way of setting a rule before doing anything with > onclick. (Onclick doesn''t activate until you let go of the clicked > button). > > So, the easiest solution (if we don''t do anything fancy with functions) > is to apply two javascript events to your submit button. > > Example > =============> <input type="submit" name="mybutton" onmousedown="this.title=1" > onclick="if(this.title!=1){return false;}" value="Submit my Form" /> > > > How it works? > =============> What happens is.. if you click the button, the onmousedown event runs > first which renames/sets the title of the button. When you let go of the > mousebutton, the onclick takes effect and checks the title to see if its > set to 1. If it is, then it submits, otherwise it returns false. > > This means that, if you pressed ENTER, onmousedown wouldn''t have renamed > the title which means the onclick will return false and not submit the > form. > > Obviously, as I know the Mootools library I''ve made a transparent method > which just adds the two events to all input=submit buttons on the page. > The inline example here is just to show you the method for copying and > pasting quickly :) > > Hope that helps someone! > Adam > www.greatbigmassive.net > > -- > Posted via http://www.ruby-forum.com/. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9700e089-59f5-4e7a-b870-8ed0ca05e4a8%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.