How can I change a form so that the Enter key is disabled for "Submit"

108 views
Skip to first unread message

Tom Stratton

unread,
Jan 29, 2015, 7:40:58 PM1/29/15
to web...@googlegroups.com
I'm finding that a lot of users are hitting Enter instead of Tab and I'm getting half-filled-in forms. I'd like to set the button to NOT default but not sure where to go about making that change.

Anyone have a solution?

Thanks

Tom

Niphlod

unread,
Jan 30, 2015, 4:34:52 PM1/30/15
to web...@googlegroups.com
there are a lot if you want to do down that path.

http://stackoverflow.com/questions/895171/prevent-users-from-submitting-form-by-hitting-enter

IMHO disabling enter is not a solution (I'm a keyboard guy and I love to send forms with enter): at the very minimum you should do a proper validation (server-side with web2py is easy). The most "elegant" way is to disable the submit button via javascript until all required fields are filled.

Tom Stratton

unread,
Feb 2, 2015, 6:02:07 PM2/2/15
to web...@googlegroups.com
Thanks -

I found several methods on SO that involved manipulation of the OUTPUT from web2py that gets rendered in the browser. Implemented a solution that was very specific to the forms that I want to have filled in.

I had hoped for a web2py specific way to manage the submit button behavior because of this observed behavior:
  • In web2py, for "list" fields, <enter> adds a new value to the list
  • in web2py, for "text" fields, <enter> creates a line break in the input.
These are great behaviors but they put the users into the habit of pressing enter and the fields that I was validating are not amenable to an a-priori decision about whether the form is completely filled in or not as blank fields are acceptable and common.

Ultimately, I disabled the enter key on a field-by-field basis using jquery and left the behavior as-is for any field with "list" in the name.

Thanks for the suggestions!

Tom
Reply all
Reply to author
Forward
0 new messages