mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Implement value
property on <select>
.
This commit is contained in:
parent
6e0d7326ab
commit
a3d4d336b7
5 changed files with 36 additions and 22 deletions
|
@ -64,6 +64,10 @@ impl HTMLOptionElement {
|
|||
self.selectedness.set(selected);
|
||||
}
|
||||
|
||||
pub fn set_dirtiness(&self, dirtiness: bool) {
|
||||
self.dirtiness.set(dirtiness);
|
||||
}
|
||||
|
||||
fn pick_if_selected_and_reset(&self) {
|
||||
if let Some(select) = self.upcast::<Node>().ancestors()
|
||||
.filter_map(Root::downcast::<HTMLSelectElement>)
|
||||
|
|
|
@ -258,6 +258,37 @@ impl HTMLSelectElementMethods for HTMLSelectElement {
|
|||
fn Remove(&self) {
|
||||
self.upcast::<Element>().Remove()
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-select-value
|
||||
fn Value(&self) -> DOMString {
|
||||
self.upcast::<Node>()
|
||||
.traverse_preorder()
|
||||
.filter_map(Root::downcast::<HTMLOptionElement>)
|
||||
.filter(|opt_elem| opt_elem.Selected())
|
||||
.map(|opt_elem| opt_elem.Value())
|
||||
.next()
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-select-value
|
||||
fn SetValue(&self, value: DOMString) {
|
||||
let mut opt_iter = self.upcast::<Node>()
|
||||
.traverse_preorder()
|
||||
.filter_map(Root::downcast::<HTMLOptionElement>);
|
||||
// Reset until we find an <option> with a matching value
|
||||
for opt in opt_iter.by_ref() {
|
||||
if opt.Value() == value {
|
||||
opt.set_selectedness(true);
|
||||
opt.set_dirtiness(true);
|
||||
break;
|
||||
}
|
||||
opt.set_selectedness(false);
|
||||
}
|
||||
// Reset remaining <option> elements
|
||||
for opt in opt_iter {
|
||||
opt.set_selectedness(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl VirtualMethods for HTMLSelectElement {
|
||||
|
|
|
@ -26,7 +26,7 @@ interface HTMLSelectElement : HTMLElement {
|
|||
|
||||
//readonly attribute HTMLCollection selectedOptions;
|
||||
// attribute long selectedIndex;
|
||||
// attribute DOMString value;
|
||||
attribute DOMString value;
|
||||
|
||||
//readonly attribute boolean willValidate;
|
||||
readonly attribute ValidityState validity;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue