Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /html/semantics/forms/the-input-element/change-to-empty-value.html - WPT Dashboard Interop Dashboard
<!doctype html>
<meta charset="utf-8">
<title>Change event when clearing an input</title>
<link rel="author" href="mailto:emilio@crisal.io" title="Emilio Cobos Álvarez">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<input type="text" value="abc">
<script>
promise_test(async function() {
let input = document.querySelector("input");
let changeFired = false;
input.addEventListener("change", () => {
changeFired = true;
}, { once: true });
input.focus();
assert_equals(document.activeElement, input, "Should focus input");
assert_false(changeFired, "Shouldn't have fired change event after focus");
input.select();
const kBackspaceKey = "\uE003";
await test_driver.send_keys(input, kBackspaceKey)
assert_false(changeFired, "Shouldn't have fired change event after select");
input.blur();
assert_true(changeFired, "Should've have fired change event after blur");
assert_equals(input.value, "", "Should've have cleared the value");
});
</script>