7

This is a quite simple issue to describe. This was tested on Firefox (3.6), IE (8) and Chrome (8).

Here is the file doesnotsubmit.html

<form>
    <input />
    <input />
</form>

When the focus is on one of the input and you press enter, nothing happens.

Below is the file doessubmit.html

<form>
    <input />
</form>

When the focus is on the input and you press enter, the form is submitted.

Any insight on this inconsistent behavior ?

I know the form lacks a submit button, and thus is not semantically correct. Anyway, the submit process was meant to automatically be handled through jQuery dialogs buttonpane's buttons, and I wouldn't know how to place an additional <input type="submit" />.

Karim
  • 71
  • 1
  • If I had to guess I would say "not submitting" was desired behavior, but they added an exception to a form with one input for the sake of websites with search fields (which this is their typical pattern). Though I'm really on speculating here... – Brad Christie Jan 28 '11 at 16:15
  • Well the insight is [here](http://stackoverflow.com/questions/1370021/enter-key-on-a-form-with-a-single-input-field-will-automatically-submit-with-get/1370314#1370314), see the link to the HTML Spec – user754151 May 15 '11 at 02:32

2 Answers2

1

There are two possible solution for this issue.

  1. The simplest solution is to add 1 more input field which will not visible to user.

  2. you can bind the keydown event of that input field, and in that function just check keyCode == 13 then preventDefault().

Ranish Karim
  • 366
  • 1
  • 8
1

user754151 is correct. This is a known bug but i guess you can get rid of it just intercepting the enter keypress event.

andreapier
  • 2,958
  • 2
  • 38
  • 50