Re:A story about <input>
by apendleton on Thursday October 22, 2015 @06:18PM
(#10435516)
I've had the best luck just globally swallowing the submit event and pretending like it doesn't exist, and deciding for myself when to submit based on clicks or keystrokes.
For example, if you have a <form> with a text field (input[type=text]) and a submit button, if you hit 'Enter' in the text field, you get a submit event, nothing surprising. But did you know you also get an artificial click event on the submit button, before the submit event?
Now what if you don't have the submit button? Then hitting the 'Enter' key would still generate a submit event, but without any artificial click event now.
OK, what if you want to have two textfields now (and still no submit button)? Then hitting 'Enter' would...you guessed it, NOT generate any submit events. No submit event, no artificial click, not even moving the focus from one text field to the other.
But what if you have a non text base input (color, date, range, etc) and hit 'Enter' on it? Yes, you get a submit event, but ONLY if you have a submit button. Otherwise no, even if you have just a single non-text based input.
And all these are just for Chrome. Other browsers behave somewhat differently.