mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Adds reset method to FormControl
This commit is contained in:
parent
f0ce2af89c
commit
a3b3295d80
2 changed files with 20 additions and 20 deletions
|
@ -346,32 +346,17 @@ impl<'a> HTMLFormElementHelpers for JSRef<'a, HTMLFormElement> {
|
||||||
// TODO: This is an incorrect way of getting controls owned
|
// TODO: This is an incorrect way of getting controls owned
|
||||||
// by the form, but good enough until html5ever lands
|
// by the form, but good enough until html5ever lands
|
||||||
for child in node.traverse_preorder() {
|
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() {
|
match child.type_id() {
|
||||||
ElementNodeTypeId(HTMLInputElementTypeId) => {
|
ElementNodeTypeId(HTMLInputElementTypeId) => {
|
||||||
let input: JSRef<HTMLInputElement> = HTMLInputElementCast::to_ref(child)
|
let input: JSRef<HTMLInputElement> = HTMLInputElementCast::to_ref(child)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let ty = input.Type();
|
input.reset()
|
||||||
|
|
||||||
match ty.as_slice() {
|
|
||||||
"radio" | "checkbox" => {
|
|
||||||
// TODO Reset radios/checkboxes here
|
|
||||||
},
|
|
||||||
"image" => (),
|
|
||||||
_ => ()
|
|
||||||
}
|
|
||||||
|
|
||||||
input.SetValue(input.DefaultValue());
|
|
||||||
}
|
}
|
||||||
// TODO HTMLKeygenElement unimplemented
|
// TODO HTMLKeygenElement unimplemented
|
||||||
/*ElementNodeTypeID(HTMLKeygenElementTypeId) => {
|
//ElementNodeTypeID(HTMLKeygenElementTypeId) => {
|
||||||
// Unimplemented
|
// // Unimplemented
|
||||||
{}
|
// {}
|
||||||
}*/
|
//}
|
||||||
ElementNodeTypeId(HTMLSelectElementTypeId) => {
|
ElementNodeTypeId(HTMLSelectElementTypeId) => {
|
||||||
// Unimplemented
|
// Unimplemented
|
||||||
{}
|
{}
|
||||||
|
@ -498,4 +483,5 @@ pub trait FormControl<'a> : Copy {
|
||||||
fn to_element(self) -> JSRef<'a, Element>;
|
fn to_element(self) -> JSRef<'a, Element>;
|
||||||
// https://html.spec.whatwg.org/multipage/forms.html#concept-fe-mutable
|
// https://html.spec.whatwg.org/multipage/forms.html#concept-fe-mutable
|
||||||
fn mutable(self) -> bool;
|
fn mutable(self) -> bool;
|
||||||
|
fn reset(self);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
// https://html.spec.whatwg.org/multipage/forms.html#the-readonly-attribute:concept-fe-mutable
|
||||||
!(self.Disabled() || self.ReadOnly())
|
!(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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue