Closed
Description
Specification: Form submission algorithm
Found in #4597
Chrome, Firefox, and Safari have a reentrancy protection for submit
event. That is to say, they don't allow starting form submission algorithm without submitted from submit() method flag in submit
event handlers.
Clicking the first submit button in the following HTML dispatches just one submit
event, and click()
call does nothing.
On the other hand, f.submit()
in submit
event should not be ignored.
A possible solution:
- has in-submit-event flag, initially false.
- It should be set to true before firing submit event, and reset to false after it.
- Add "If the submitted from() method flag is not set and in-submit-event flag is true, then return." before step 6 of form submission algorithm.
Note: Edge dispatches two submit
events in the example case. It might have a different reentrancy protection.
<!DOCTYPE html>
<body>
<form action="http://www.google.com/search" target="_blank">
<input type=hidden name=q value=v0>
<input type=submit>
<button type=submit>Another submit</button>
</form>
<pre></pre>
<script>
function log(str) {
document.querySelector('pre').textContent += str + '\n';
}
let f = document.querySelector('form');
f.addEventListener('submit', e => {
log('Event: ' + e.type);
let hidden = f.querySelector('[name=q]');
hidden.value = 'v1';
document.querySelector('button').click();
log('Called click()');
hidden.value = 'v2';
});
</script>
</body>