diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index 090aa8553bf..26a30d07599 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -634,8 +634,7 @@ impl HTMLFormElement { // {} //} NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLSelectElement)) => { - // Unimplemented - {} + child.downcast::().unwrap().reset(); } NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTextAreaElement)) => { child.downcast::().unwrap().reset(); diff --git a/components/script/dom/htmlselectelement.rs b/components/script/dom/htmlselectelement.rs index 34c9187b644..03d10e117f4 100644 --- a/components/script/dom/htmlselectelement.rs +++ b/components/script/dom/htmlselectelement.rs @@ -84,6 +84,16 @@ impl HTMLSelectElement { HTMLSelectElementBinding::Wrap) } + // https://html.spec.whatwg.org/multipage/#the-select-element:concept-form-reset-control + pub fn reset(&self) { + let node = self.upcast::(); + for opt in node.traverse_preorder().filter_map(Root::downcast::) { + opt.set_selectedness(opt.DefaultSelected()); + opt.set_dirtiness(false); + } + self.ask_for_reset(); + } + // https://html.spec.whatwg.org/multipage/#ask-for-a-reset pub fn ask_for_reset(&self) { if self.Multiple() { diff --git a/tests/wpt/metadata/html/semantics/forms/resetting-a-form/reset-form.html.ini b/tests/wpt/metadata/html/semantics/forms/resetting-a-form/reset-form.html.ini index c2ff574ea9f..7a0f14f6953 100644 --- a/tests/wpt/metadata/html/semantics/forms/resetting-a-form/reset-form.html.ini +++ b/tests/wpt/metadata/html/semantics/forms/resetting-a-form/reset-form.html.ini @@ -1,11 +1,11 @@ [reset-form.html] type: testharness - [Resetting the form by calling the reset() method] + [Resetting by calling the reset() method] expected: FAIL - [Resetting the form by clicking the button in reset status] + [Resetting by clicking the button in reset status] expected: FAIL - [Resetting the form by clicking the input in reset status] + [Resetting by clicking the input in reset status] expected: FAIL diff --git a/tests/wpt/web-platform-tests/html/semantics/forms/resetting-a-form/reset-form.html b/tests/wpt/web-platform-tests/html/semantics/forms/resetting-a-form/reset-form.html index b74b52c46e4..7654cedbeb1 100644 --- a/tests/wpt/web-platform-tests/html/semantics/forms/resetting-a-form/reset-form.html +++ b/tests/wpt/web-platform-tests/html/semantics/forms/resetting-a-form/reset-form.html @@ -87,10 +87,25 @@ function runTest(reset, description) { assert_false(document.getElementById("rd2").checked, "The checked attribute of the input element in radio should be false."); assert_true(document.getElementById("cb1").checked, "The checked attribute of the input element in checkbox should be true."); assert_false(document.getElementById("cb2").checked, "The checked attribute of the input element in checkbox should be false."); + }, "Resetting " + description); + + test(function() { + setPreconditions("Setting preconditions for resetting " + description); + reset(); assert_equals(document.getElementById("ta").value, document.getElementById("ta").textContent, "The value attribute of the textarea element should be reset."); assert_equals(document.getElementById("ta").value, "abc", "The value attribute of the textarea element should be 'abc'."); + }, "Resetting