aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/validation.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/validation.rs')
-rwxr-xr-xcomponents/script/dom/validation.rs23
1 files changed, 14 insertions, 9 deletions
diff --git a/components/script/dom/validation.rs b/components/script/dom/validation.rs
index ab92d5b07f5..dadef038600 100755
--- a/components/script/dom/validation.rs
+++ b/components/script/dom/validation.rs
@@ -17,10 +17,10 @@ use crate::dom::validitystate::{ValidationFlags, ValidityState};
pub trait Validatable {
fn as_element(&self) -> ∈
- // https://html.spec.whatwg.org/multipage/#dom-cva-validity
+ /// <https://html.spec.whatwg.org/multipage/#dom-cva-validity>
fn validity_state(&self) -> DomRoot<ValidityState>;
- // https://html.spec.whatwg.org/multipage/#candidate-for-constraint-validation
+ /// <https://html.spec.whatwg.org/multipage/#candidate-for-constraint-validation>
fn is_instance_validatable(&self) -> bool;
// Check if element satisfies its constraints, excluding custom errors
@@ -28,9 +28,14 @@ pub trait Validatable {
ValidationFlags::empty()
}
- // https://html.spec.whatwg.org/multipage/#check-validity-steps
+ /// <https://html.spec.whatwg.org/multipage/#concept-fv-valid>
+ fn satisfies_constraints(&self) -> bool {
+ self.validity_state().invalid_flags().is_empty()
+ }
+
+ /// <https://html.spec.whatwg.org/multipage/#check-validity-steps>
fn check_validity(&self) -> bool {
- if self.is_instance_validatable() && !self.validity_state().invalid_flags().is_empty() {
+ if self.is_instance_validatable() && !self.satisfies_constraints() {
self.as_element()
.upcast::<EventTarget>()
.fire_cancelable_event(atom!("invalid"));
@@ -40,15 +45,14 @@ pub trait Validatable {
}
}
- // https://html.spec.whatwg.org/multipage/#report-validity-steps
+ /// <https://html.spec.whatwg.org/multipage/#report-validity-steps>
fn report_validity(&self) -> bool {
// Step 1.
if !self.is_instance_validatable() {
return true;
}
- let flags = self.validity_state().invalid_flags();
- if flags.is_empty() {
+ if self.satisfies_constraints() {
return true;
}
@@ -60,6 +64,7 @@ pub trait Validatable {
// Step 1.2.
if !event.DefaultPrevented() {
+ let flags = self.validity_state().invalid_flags();
println!(
"Validation error: {}",
validation_message_for_flags(&self.validity_state(), flags)
@@ -73,7 +78,7 @@ pub trait Validatable {
false
}
- // https://html.spec.whatwg.org/multipage/#dom-cva-validationmessage
+ /// <https://html.spec.whatwg.org/multipage/#dom-cva-validationmessage>
fn validation_message(&self) -> DOMString {
if self.is_instance_validatable() {
let flags = self.validity_state().invalid_flags();
@@ -84,7 +89,7 @@ pub trait Validatable {
}
}
-// https://html.spec.whatwg.org/multipage/#the-datalist-element%3Abarred-from-constraint-validation
+/// <https://html.spec.whatwg.org/multipage/#the-datalist-element%3Abarred-from-constraint-validation>
pub fn is_barred_by_datalist_ancestor(elem: &Node) -> bool {
elem.upcast::<Node>()
.ancestors()