mirror of
https://github.com/servo/servo.git
synced 2025-07-26 00:30:22 +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;
|
||||
|
|
|
@ -3711,9 +3711,6 @@
|
|||
[HTMLSelectElement interface: attribute selectedIndex]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLSelectElement interface: attribute value]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLSelectElement interface: attribute willValidate]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -3744,9 +3741,6 @@
|
|||
[HTMLSelectElement interface: document.createElement("select") must inherit property "selectedIndex" with the proper type (18)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLSelectElement interface: document.createElement("select") must inherit property "value" with the proper type (19)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLSelectElement interface: document.createElement("select") must inherit property "willValidate" with the proper type (20)]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,20 +1,5 @@
|
|||
[htmloptionscollection.html]
|
||||
type: testharness
|
||||
[Setting length to longer value]
|
||||
expected: FAIL
|
||||
|
||||
[Insert <p><option>6</option></p> into <select>]
|
||||
expected: FAIL
|
||||
|
||||
[Insert <select><option>6</option></select> into <select>]
|
||||
expected: FAIL
|
||||
|
||||
[Insert <optgroup><option>6</option></optgroup> into <select>]
|
||||
expected: FAIL
|
||||
|
||||
[Insert <optgroup><optgroup><option>6</option></optgroup></optgroup> into <select>]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLOptionsCollection.add method insert HTMLOptionElement Option element]
|
||||
expected: FAIL
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue