Skip to content

Commit

Permalink
Implement "reset algorithm" for <select>.
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Oct 20, 2016
1 parent 6c28d44 commit a45e1d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions components/script/dom/htmlformelement.rs
Expand Up @@ -634,8 +634,7 @@ impl HTMLFormElement {
// {}
//}
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLSelectElement)) => {
// Unimplemented
{}
child.downcast::<HTMLSelectElement>().unwrap().reset();
}
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTextAreaElement)) => {
child.downcast::<HTMLTextAreaElement>().unwrap().reset();
Expand Down
10 changes: 10 additions & 0 deletions components/script/dom/htmlselectelement.rs
Expand Up @@ -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::<Node>();
for opt in node.traverse_preorder().filter_map(Root::downcast::<HTMLOptionElement>) {
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() {
Expand Down

0 comments on commit a45e1d9

Please sign in to comment.