Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upHTML input value #9514
HTML input value #9514
Conversation
| fn default() -> InputValueMode { InputValueMode::Default } | ||
| } | ||
|
|
||
| impl InputValueMode { |
This comment has been minimized.
This comment has been minimized.
|
|
Thanks for the feedback! I broke a bunch of tests in: |
|
OK, I'm stuck. 9a4b26f passes the radionodelist test and the I tried to get it test passing by setting the value to the textinput value when the type attribute changes (in
|
| } else { | ||
| input.upcast::<Element>() | ||
| .get_attribute(&ns!(), &atom!("value")) | ||
| .map_or_else(|| default, |
This comment has been minimized.
This comment has been minimized.
|
Could you also provide step annotations for the functions that you've wrote? It's hard to follow which part of the spec you're implementing. |
| @@ -292,14 +352,12 @@ impl HTMLInputElementMethods for HTMLInputElement { | |||
|
|
|||
| // https://html.spec.whatwg.org/multipage/#dom-input-value | |||
| fn Value(&self) -> DOMString { | |||
| self.textinput.borrow().get_content() | |||
| InputValueMode::from_input_element(&self).get_value(self) | |||
This comment has been minimized.
This comment has been minimized.
KiChjang
Feb 5, 2016
Member
I'm not sure how I missed this, but this style is kind of weird. I'd expect InputValueMode to be a field in HTMLInputElement, and this method would just be a call to self.get_value(). Here you're constructing a new InputValueMode every time you get or set the value of an HTMLInputElement, and then calling a method on the InputValueMode, supplying it with an instance of HTMLInputElement.
| } | ||
|
|
||
| fn set_value(&self, input: &HTMLInputElement, value: DOMString) { | ||
| let element = input.upcast::<Element>(); |
This comment has been minimized.
This comment has been minimized.
KiChjang
Feb 5, 2016
Member
I see no value in putting the let-binding here, since element is only used in the else-body.
|
I suspect that the test failures are because of the changes between |
|
Ah! I thought only content attributes were called attributes. I made the suggested changes and the input and raidonodelist tests pass, but the implementation is wrong since I need to find out if the simple list iterator does a tree order traversal (pre-order, depth-first traversal of DOM nodes) and whether remove attribute on an |
| // assert_equals(document.getElementById("r1").value, -39); // but got string "1" | ||
|
|
||
| rdoList.value = "on"; | ||
| // expected "1" but got "2" |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
g-k
Feb 17, 2016
Author
Contributor
I will. This is a WIP branch.
I just thought it was interesting, because it seems like IDL attribute has the right value before it is set to "on".
|
|
||
| // On setting, if the new value is the empty string, it | ||
| // must empty the list of selected files; otherwise, it | ||
| // must throw an InvalidStateError exception. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
g-k
Feb 17, 2016
Author
Contributor
I might be misreading the spec or looking in the wrong place, but I don't see any step numbers on: https://html.spec.whatwg.org/multipage/forms.html#dom-input-value
| // must return that attribute's value; otherwise, it must | ||
| // return the string "on" (for default/on mode) | ||
| ValueMode::DefaultOn => { | ||
| let content = self.textinput.borrow().get_content(); |
This comment has been minimized.
This comment has been minimized.
KiChjang
Feb 16, 2016
Member
This should instead upcast itself to an Element and grab the content attribute value from it.
Same for ValueMode::Default.
This comment has been minimized.
This comment has been minimized.
g-k
Feb 17, 2016
Author
Contributor
My bad, I didn't realize the red text in the spec are links and I thought they were talking about the IDL attribute.
Confusingly the bold red text is talking about an IDL attribute.
8fc5c64
to
7b21d8e
| |a| DOMString::from(a.summarize().value)), | ||
| ValueMode::DefaultOn => | ||
| self.upcast::<Element>() | ||
| .get_attribute(&ns!(), &atom!("value")) |
This comment has been minimized.
This comment has been minimized.
| ValueMode::Filename | ValueMode::Value => self.textinput.borrow().get_content(), | ||
| ValueMode::Default => | ||
| self.upcast::<Element>() | ||
| .get_attribute(&ns!(), &atom!("value")) |
This comment has been minimized.
This comment has been minimized.
| @@ -292,12 +320,32 @@ impl HTMLInputElementMethods for HTMLInputElement { | |||
|
|
|||
| // https://html.spec.whatwg.org/multipage/#dom-input-value | |||
| fn Value(&self) -> DOMString { | |||
| self.textinput.borrow().get_content() | |||
| match self.get_value_mode() { | |||
| ValueMode::Filename | ValueMode::Value => self.textinput.borrow().get_content(), | |||
This comment has been minimized.
This comment has been minimized.
KiChjang
Feb 17, 2016
Member
This is actually much more involved than just returning the textinput.The spec says the following for value:
On getting, it must return the current value of the element. On setting, it must set the element's value to the new value, set the element's dirty value flag to true, invoke the value sanitization algorithm, if the element's type attribute's current state defines one, and then, if the element has a text entry cursor position, should move the text entry cursor position to the end of the text field, unselecting any selected text and resetting the selection direction to none.
And the following for filename:
On getting, it must return the string "C:\fakepath" followed by the name of the first file in the list of selected files, if any, or the empty string if the list is empty. On setting, if the new value is the empty string, it must empty the list of selected files; otherwise, it must throw an InvalidStateError exception.
| } | ||
|
|
||
| // https://html.spec.whatwg.org/multipage/#input-type-attr-summary | ||
| fn get_value_mode_for_input_type(input_type: InputType) -> ValueMode { |
This comment has been minimized.
This comment has been minimized.
KiChjang
Feb 17, 2016
Member
Why is this written in a functional style? The HTMLInputElement has all the necessary information about its own input type.
This comment has been minimized.
This comment has been minimized.
| self.SetValue(DOMString::from("")); | ||
| } | ||
|
|
||
| if new_type == InputType::InputRadio { |
This comment has been minimized.
This comment has been minimized.
| } else if old_value_mode != ValueMode::Value && new_value_mode == ValueMode::Value { | ||
| // Step 2 | ||
| self.SetValue(self.upcast::<Element>() | ||
| .get_attribute(&ns!(), &atom!("value")) |
This comment has been minimized.
This comment has been minimized.
HTML input value Ready for review. Fixes #9455. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9514) <!-- Reviewable:end -->
|
|
|
@bors-servo retry #9148 |
|
|
|
|
|
@bors-servo retry |
HTML input value Ready for review. Fixes #9455. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9514) <!-- Reviewable:end -->
|
|
|
@bors-servo retry |
HTML input value Ready for review. Fixes #9455. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9514) <!-- Reviewable:end -->
|
|
According to step 3 of https://html.spec.whatwg.org/multipage/forms.html#input-type-change a value mode transition from non-filename to filename should update the input internal value state to the empty string. According to https://html.spec.whatwg.org/multipage/forms.html#dom-input-value a subsequent read of the value IDL attribute should return the empty string (assuming no selected files). Refs: servo/servo#9514
g-k commentedFeb 3, 2016
Ready for review.
Fixes #9455.