Commit 1153513c authored by Joey Arhar's avatar Joey Arhar Committed by Commit Bot

Fix form submission for <button>s with children

Form submission stopped working after crrev.com/c/1850358 when using
event.preventDefault() and form.submit() in a click event handler for a
<button type=submit> when the button has child elements and the click
was made on one of the child elements.

Bug: 1020086
Change-Id: I8976298ac56a64ff7033cb2f7b46ee5116229464
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1896050Reviewed-by: default avatarMason Freed <masonfreed@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711918}
parent 92bafbfe
......@@ -348,7 +348,8 @@ inline void EventDispatcher::DispatchEventPostProcess(
// preventing default handling, the detail of which handlers are called is an
// internal implementation detail and not part of the DOM.
if (event_->defaultPrevented()) {
node_->DidPreventDefault(*event_);
if (activation_target)
activation_target->DidPreventDefault(*event_);
} else if (!event_->DefaultHandled() && is_trusted_or_click) {
// Non-bubbling events call only one default event handler, the one for the
// target.
......
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="author" title="Joey Arhar" href="mailto:jarhar@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<iframe name=frame1 id=frame1></iframe>
<form id=form1 target=frame1 action="does_not_exist.html">
<button id=submitbutton type=submit>
<div id=buttonchilddiv>
button child div text
</div>
</button>
</form>
<script>
async_test(t => {
window.addEventListener('load', () => {
const frame1 = document.getElementById('frame1');
frame1.addEventListener('load', t.step_func_done(() => {}));
const submitButton = document.getElementById('submitbutton');
submitButton.addEventListener('click', event => {
event.preventDefault();
const form = document.getElementById('form1');
form.submit();
});
const buttonChildDiv = document.getElementById('buttonchilddiv');
buttonChildDiv.click();
});
}, 'This test will pass if a form navigation successfully occurs when clicking a child element of a <button type=submit> element with a onclick event handler which prevents the default form submission and manually calls form.submit() instead.');
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment