9

Problem:

I never specify a submit button, as I use ajax to submit my forms, but some forms have an auto-submit feature regardless.

Background:

Throughout my application I have instances when clicking the enter button will auto-submit a form and other instances where it will do nothing. For example; there are times where I will need to capture the "enter" button to get an auto-submit but other times where it seems to just happen on it's own and I have not found the pattern. Except that the dynamically created forms seem to have the auto-submit feature but static ones do not? Does anyone else have a similar issue.

Example:

All of my forms have the submit button removed and I specify no target or action elements as seen below. All of the forms have their data transmitted through AJAX.

<form id="ajaxForm">
<input>
</form>
<button>ButtonOutSideForm</button>

Not looking for a way to prevent auto-submit

I already know about "onsubmit = return false" and e.preventDefault. I'm not looking for a way to disable auto-submit. My question is why does it's presence seem arbitrary. Thanks.

Usman Mutawakil
  • 4,993
  • 9
  • 43
  • 80
  • Just a thought, but have you looked at your tabindex on the page (both before and after the AJAX)? – Sablefoste May 01 '13 at 02:11
  • Sorry... of course `tabindex`. If you only have them on the AJAX loaded form, I would expect that a Return would complete the form. If you have them both on and off the AJAX, I am not sure what you might get. – Sablefoste May 01 '13 at 02:15
  • Also note that you don't actually need a submit button for the form to submit: http://tjvantoll.com/2013/01/01/enter-should-submit-forms-stop-messing-with-that/ "So, in a form with no submit buttons, implicit submission will be done if only one input is present." – LouD May 01 '13 at 02:18
  • @LouD That article seems to suggest that it's could practice to use "implicit submission". It doesn't say anything about how to do it or why it isn't standard in every form. – Usman Mutawakil May 01 '13 at 02:22
  • 1
    Have you read http://stackoverflow.com/questions/925334/how-is-the-default-submit-button-on-an-html-form-determined?rq=1 – j08691 May 01 '13 at 02:25
  • @j08691 I just did. Its about the default submit button and not what happens when a user clicks enter. If I understand correctly, it discuses what handlers should fire when a browser is submitted using form.submit() verses the actual submit button. It similar but really unrelated to my question. It doesn't say anything about what determines the default behavior on clicking the enter button, but instead discusses default behavior when firing submit(). Thanks anyway. – Usman Mutawakil May 01 '13 at 03:50
  • Actually if you read the accepted answer you'll see it does discuss the enter button. – j08691 May 01 '13 at 11:59
  • 1
    @Usman Mutawakil The point of the article is that there is no single standard. The spec says that there should be different functionality based on the types of fields you have in the form. In your case, that form only has a single input so it will auto-submit regardless of whether you have a submit button – LouD May 01 '13 at 13:55
  • Maybe it would clear things up if you include some examples of the actual input elements you are using and which elements have focus when you hit enter. – LouD May 01 '13 at 14:02
  • @LouD. Your last point about there being a single input seems to be the answer. I read that article again guys and I must say it does not say anything about when auto-submit should take place and when it shouldn't. That post is about what submit button should fire when you have multiple submit buttons in the same form and a user has clicked enter. The accepted answer says its up to the spec. I'm not trying to be rude but I think you guys should read that article again. My question = No submit button. Their question = Lots of submit buttons. – Usman Mutawakil May 01 '13 at 14:46

1 Answers1

6

As LouD pointed out. Some browsers will auto-submit if the form only contains one input element.Why does forms with single input field submit upon pressing enter key in input

Community
  • 1
  • 1
Usman Mutawakil
  • 4,993
  • 9
  • 43
  • 80