diff options
author | bors-servo <servo-ops@mozilla.com> | 2020-04-02 08:07:30 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-02 08:07:30 -0400 |
commit | a651bad838e0fc87ea199ff0ec81d53a97bd61dd (patch) | |
tree | f3dac563783cfeaa5ca69851c426d7e7b4dff9c3 /components/script/dom/htmlfieldsetelement.rs | |
parent | e47e884cc738a5cb472416a4fbdd9d2a32a2385c (diff) | |
parent | 779552ee7ddbbde1055c7202e16b9a13c3961988 (diff) | |
download | servo-a651bad838e0fc87ea199ff0ec81d53a97bd61dd.tar.gz servo-a651bad838e0fc87ea199ff0ec81d53a97bd61dd.zip |
Auto merge of #25447 - teapotd:form-validation, r=jdm
Form constraint validation
It's almost done, there are few things remaining:
- ~Range underflow, range overflow and step mismatch implementation require #25405~
- ~There are some test failures due to missing DOM parts (#25003)~
- ~`pattern` attribute uses JS regexp syntax. Currently I used regex crate, but it's probably incompatible. Should we use SpiderMonkey's regexp via jsapi?~
- Currently validation errors are reported using `println!`. Are there any better options?
- ~["While the user interface is representing input that the user agent cannot convert to punycode, the control is suffering from bad input."](https://html.spec.whatwg.org/multipage/#e-mail-state-(type%3Demail)%3Asuffering-from-bad-input)~
r? @jdm
---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #11444
- [x] There are tests for these changes
Diffstat (limited to 'components/script/dom/htmlfieldsetelement.rs')
-rw-r--r-- | components/script/dom/htmlfieldsetelement.rs | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/components/script/dom/htmlfieldsetelement.rs b/components/script/dom/htmlfieldsetelement.rs index a277cf8e2ec..b2b05cbc5c4 100644 --- a/components/script/dom/htmlfieldsetelement.rs +++ b/components/script/dom/htmlfieldsetelement.rs @@ -14,6 +14,7 @@ use crate::dom::htmlelement::HTMLElement; use crate::dom::htmlformelement::{FormControl, HTMLFormElement}; use crate::dom::htmllegendelement::HTMLLegendElement; use crate::dom::node::{window_from_node, Node, ShadowIncluding}; +use crate::dom::validation::Validatable; use crate::dom::validitystate::ValidityState; use crate::dom::virtualmethods::VirtualMethods; use dom_struct::dom_struct; @@ -25,6 +26,7 @@ use style::element_state::ElementState; pub struct HTMLFieldSetElement { htmlelement: HTMLElement, form_owner: MutNullableDom<HTMLFormElement>, + validity_state: MutNullableDom<ValidityState>, } impl HTMLFieldSetElement { @@ -41,6 +43,7 @@ impl HTMLFieldSetElement { document, ), form_owner: Default::default(), + validity_state: Default::default(), } } @@ -75,12 +78,6 @@ impl HTMLFieldSetElementMethods for HTMLFieldSetElement { HTMLCollection::create(&window, self.upcast(), filter) } - // https://html.spec.whatwg.org/multipage/#dom-cva-validity - fn Validity(&self) -> DomRoot<ValidityState> { - let window = window_from_node(self); - ValidityState::new(&window, self.upcast()) - } - // https://html.spec.whatwg.org/multipage/#dom-fieldset-disabled make_bool_getter!(Disabled, "disabled"); @@ -97,6 +94,36 @@ impl HTMLFieldSetElementMethods for HTMLFieldSetElement { fn GetForm(&self) -> Option<DomRoot<HTMLFormElement>> { self.form_owner() } + + // https://html.spec.whatwg.org/multipage/#dom-cva-willvalidate + fn WillValidate(&self) -> bool { + self.is_instance_validatable() + } + + // https://html.spec.whatwg.org/multipage/#dom-cva-validity + fn Validity(&self) -> DomRoot<ValidityState> { + self.validity_state() + } + + // https://html.spec.whatwg.org/multipage/#dom-cva-checkvalidity + fn CheckValidity(&self) -> bool { + self.check_validity() + } + + // https://html.spec.whatwg.org/multipage/#dom-cva-reportvalidity + fn ReportValidity(&self) -> bool { + self.report_validity() + } + + // https://html.spec.whatwg.org/multipage/#dom-cva-validationmessage + fn ValidationMessage(&self) -> DOMString { + self.validation_message() + } + + // https://html.spec.whatwg.org/multipage/#dom-cva-setcustomvalidity + fn SetCustomValidity(&self, error: DOMString) { + self.validity_state().set_custom_error_message(error); + } } impl VirtualMethods for HTMLFieldSetElement { @@ -185,3 +212,19 @@ impl FormControl for HTMLFieldSetElement { self.upcast::<Element>() } } + +impl Validatable for HTMLFieldSetElement { + fn as_element(&self) -> &Element { + self.upcast() + } + + fn validity_state(&self) -> DomRoot<ValidityState> { + self.validity_state + .or_init(|| ValidityState::new(&window_from_node(self), self.upcast())) + } + + fn is_instance_validatable(&self) -> bool { + // fieldset is not a submittable element (https://html.spec.whatwg.org/multipage/#category-submit) + false + } +} |