mirror of
https://github.com/servo/servo
synced 2026-05-05 06:32:13 +02:00
html form validation initial steps with test html file, added stub methods, added code to handle validations
This commit is contained in:
45
components/script/dom/htmlformelement.rs
Normal file → Executable file
45
components/script/dom/htmlformelement.rs
Normal file → Executable file
@@ -36,6 +36,7 @@ use dom::htmloutputelement::HTMLOutputElement;
|
||||
use dom::htmlselectelement::HTMLSelectElement;
|
||||
use dom::htmltextareaelement::HTMLTextAreaElement;
|
||||
use dom::node::{Node, document_from_node, window_from_node};
|
||||
use dom::validitystate::ValidationFlags;
|
||||
use dom::virtualmethods::VirtualMethods;
|
||||
use encoding::EncodingRef;
|
||||
use encoding::all::UTF_8;
|
||||
@@ -469,12 +470,22 @@ impl HTMLFormElement {
|
||||
// form, refactor this when html5ever's form owner PR lands
|
||||
// Step 1-3
|
||||
let invalid_controls = node.traverse_preorder().filter_map(|field| {
|
||||
if let Some(_el) = field.downcast::<Element>() {
|
||||
None // Remove this line if you decide to refactor
|
||||
|
||||
// XXXKiChjang: Form control elements should each have a candidate_for_validation
|
||||
// and satisfies_constraints methods
|
||||
|
||||
if let Some(el) = field.downcast::<Element>() {
|
||||
if el.disabled_state() {
|
||||
None
|
||||
} else {
|
||||
let validatable = match el.as_maybe_validatable() {
|
||||
Some(v) => v,
|
||||
None => return None
|
||||
};
|
||||
if !validatable.is_instance_validatable() {
|
||||
None
|
||||
} else if validatable.validate(ValidationFlags::empty()) {
|
||||
None
|
||||
} else {
|
||||
Some(FormSubmittableElement::from_element(&el))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -700,7 +711,7 @@ pub enum FormSubmittableElement {
|
||||
// KeygenElement(&'a HTMLKeygenElement),
|
||||
ObjectElement(Root<HTMLObjectElement>),
|
||||
SelectElement(Root<HTMLSelectElement>),
|
||||
TextAreaElement(Root<HTMLTextAreaElement>)
|
||||
TextAreaElement(Root<HTMLTextAreaElement>),
|
||||
}
|
||||
|
||||
impl FormSubmittableElement {
|
||||
@@ -713,6 +724,26 @@ impl FormSubmittableElement {
|
||||
FormSubmittableElement::TextAreaElement(ref textarea) => textarea.upcast()
|
||||
}
|
||||
}
|
||||
|
||||
fn from_element(element: &Element) -> FormSubmittableElement {
|
||||
if let Some(input) = element.downcast::<HTMLInputElement>() {
|
||||
FormSubmittableElement::InputElement(Root::from_ref(&input))
|
||||
}
|
||||
else if let Some(input) = element.downcast::<HTMLButtonElement>() {
|
||||
FormSubmittableElement::ButtonElement(Root::from_ref(&input))
|
||||
}
|
||||
else if let Some(input) = element.downcast::<HTMLObjectElement>() {
|
||||
FormSubmittableElement::ObjectElement(Root::from_ref(&input))
|
||||
}
|
||||
else if let Some(input) = element.downcast::<HTMLSelectElement>() {
|
||||
FormSubmittableElement::SelectElement(Root::from_ref(&input))
|
||||
}
|
||||
else if let Some(input) = element.downcast::<HTMLTextAreaElement>() {
|
||||
FormSubmittableElement::TextAreaElement(Root::from_ref(&input))
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, HeapSizeOf)]
|
||||
|
||||
Reference in New Issue
Block a user