Disabling a submit button in its onclick handler prevents form submission
Reported by
mendesj...@gmail.com,
Sep 21
|
||||
Issue descriptionChrome Version : Version 68.0.3440.75 (Official Build) (64-bit) URLs (if applicable) : https://jsfiddle.net/mendesjuan/jfauzkh8/ https://stackoverflow.com/a/52443415/227299 Other browsers tested: Add OK or FAIL, along with the version, after other browsers where you have tested this issue: Safari Version 12.0 (13606.2.11): FAIL Canary: FAIL Firefox: OK IE11: OK What steps will reproduce the problem? (1) Have a <form> with a <button type="submit"> inside that has an inline click handler to disable the submit button (2) Click the submit button What is the expected result? The form is submitted and the button is disabled while the page is waiting. What happens instead? The button is disabled but the form never submits. Additional information This bug does not happen if you use addEventListener on Chrome, but still happens in Safari. If you handle it in the form.onsubmit inline, the the form does submit.
,
Sep 21
,
Sep 23
,
Sep 25
The behavior of Chrome and Safari is correct according to the specification. https://html.spec.whatwg.org/multipage/form-elements.html#the-button-element:the-button-element-2 > if this element is not disabled,
,
Sep 27
Then why is the behavior different when registering an event handler with JavaScript? Is that a bug?
,
Sep 28
I didn't see any behavior difference between onclick= and addEventListener('click', ...).
,
Sep 28
The fiddle that I mentioned in the bug behaves differently, https://jsfiddle.net/mendesjuan/jfauzkh8/ . It has; * An example of setting it through attributes, where the form doesn't submit * An example of setting it with addEventListener, where the form does submit Did you look at it and the explanation in the stack overflow posts? Also note that the behavior in FF and IE is consistent. Chrome/Safari have problems.
,
Oct 1
> * An example of setting it with addEventListener, where the form does submit No. https://jsfiddle.net/mendesjuan/jfauzkh8/ doesn't have addEventListener.
,
Oct 1
Sorry. Even the example I had in the SO question mentioned, `addEventListener` also stops the form from submitting (submit event from being fired). I will note in the SO question that the behavior is accurate according to the spec, inconsistent with IE and FF and that the correct thing to do anyway is to handle it in the submit event. Thanks. |
||||
►
Sign in to add a comment |
||||
Comment 1 by mendesj...@gmail.com
, Sep 21