implement range input sanitization

This commit is contained in:
tigercosmos 2018-01-14 00:01:47 +08:00
parent 525758ea5e
commit b29230bd76
6 changed files with 75 additions and 19 deletions

View file

@ -1047,11 +1047,17 @@ impl HTMLInputElement {
}
InputType::Number => {
let mut textinput = self.textinput.borrow_mut();
if !textinput.single_line_content().is_valid_number_string() {
if !textinput.single_line_content().is_valid_floating_point_number_string() {
textinput.single_line_content_mut().clear();
}
}
// TODO: Implement more value sanitization algorithms for different types of inputs
// https://html.spec.whatwg.org/multipage/#range-state-(type=range):value-sanitization-algorithm
InputType::Range => {
self.textinput
.borrow_mut()
.single_line_content_mut()
.set_best_representation_of_the_floating_point_number();
}
_ => ()
}
}