diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs
index a08b8eec270..8f5b0180c02 100644
--- a/components/script/dom/htmlformelement.rs
+++ b/components/script/dom/htmlformelement.rs
@@ -346,32 +346,17 @@ impl<'a> HTMLFormElementHelpers for JSRef<'a, HTMLFormElement> {
// TODO: This is an incorrect way of getting controls owned
// by the form, but good enough until html5ever lands
for child in node.traverse_preorder() {
- // TODO This is the wrong place to do this. Each resettable
- // element should implement its own reset method (trait?)
- //
- // List of resettable elements:
- // https://html.spec.whatwg.org/multipage/forms.html#category-reset
match child.type_id() {
ElementNodeTypeId(HTMLInputElementTypeId) => {
let input: JSRef = HTMLInputElementCast::to_ref(child)
.unwrap();
- let ty = input.Type();
-
- match ty.as_slice() {
- "radio" | "checkbox" => {
- // TODO Reset radios/checkboxes here
- },
- "image" => (),
- _ => ()
- }
-
- input.SetValue(input.DefaultValue());
+ input.reset()
}
// TODO HTMLKeygenElement unimplemented
- /*ElementNodeTypeID(HTMLKeygenElementTypeId) => {
- // Unimplemented
- {}
- }*/
+ //ElementNodeTypeID(HTMLKeygenElementTypeId) => {
+ // // Unimplemented
+ // {}
+ //}
ElementNodeTypeId(HTMLSelectElementTypeId) => {
// Unimplemented
{}
@@ -498,4 +483,5 @@ pub trait FormControl<'a> : Copy {
fn to_element(self) -> JSRef<'a, Element>;
// https://html.spec.whatwg.org/multipage/forms.html#concept-fe-mutable
fn mutable(self) -> bool;
+ fn reset(self);
}
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs
index 12d6e11a639..51280d27759 100644
--- a/components/script/dom/htmlinputelement.rs
+++ b/components/script/dom/htmlinputelement.rs
@@ -571,6 +571,20 @@ impl<'a> FormControl<'a> for JSRef<'a, HTMLInputElement> {
// https://html.spec.whatwg.org/multipage/forms.html#the-readonly-attribute:concept-fe-mutable
!(self.Disabled() || self.ReadOnly())
}
+
+ fn reset(self) {
+ let ty = self.Type();
+
+ match ty.as_slice() {
+ "radio" | "checkbox" => {
+ // TODO Reset radios/checkboxes here
+ },
+ "image" => (),
+ _ => ()
+ }
+
+ self.SetValue(self.DefaultValue());
+ }
}