-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement HTMLFormElement::checkValidity and all HTMLInputElement “suffering from being missing” constraints (client-side form validation) #3674
base: master
Are you sure you want to change the base?
Conversation
97ee7be
to
fbb15a0
Compare
This change implements the requirements from the HTML spec at https://html.spec.whatwg.org/#statically-validate-the-constraints and https://html.spec.whatwg.org/#dom-form-checkvalidity — the parts of the HTML constraint validation API (aka “client-side form validation”) https://html.spec.whatwg.org/#the-constraint-validation-api for HTMLFormElement itself — as well as the code for the requirements at https://html.spec.whatwg.org/#check-validity-steps, which are the shared requirements for the checkValidity method for individual form controls.
fbb15a0
to
8833b0d
Compare
This change implements all required “suffering from being missing” constraints https://html.spec.whatwg.org/#suffering-from-being-missing for HTMLInputElement.
8833b0d
to
915934f
Compare
@@ -561,11 +561,49 @@ unsigned HTMLFormElement::length() const | |||
return elements()->length(); | |||
} | |||
|
|||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#statically-validate-the-constraints | |||
HTMLFormElement::StaticValidationResult HTMLFormElement::statically_validate_contraints() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: contraints -> constraints
VERIFY(is<FormAssociatedElement>(*element)); | ||
auto& field = dynamic_cast<FormAssociatedElement&>(*element); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 2 lines can be simplified to auto& field = as<FormAssociatedElement>(*element);
@@ -2525,8 +2525,7 @@ WebIDL::ExceptionOr<void> HTMLInputElement::step_up_or_down(bool is_down, WebIDL | |||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-checkvalidity | |||
WebIDL::ExceptionOr<bool> HTMLInputElement::check_validity() | |||
{ | |||
dbgln("(STUBBED) HTMLInputElement::check_validity(). Called on: {}", debug_description()); | |||
return true; | |||
return dynamic_cast<FormAssociatedElement&>(*this).check_validity(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this method gets renamed, the cast should become unnecessary.
@@ -226,6 +226,20 @@ WebIDL::ExceptionOr<void> FormAssociatedElement::set_form_action(String const& v | |||
return html_element.set_attribute(HTML::AttributeNames::formaction, value); | |||
} | |||
|
|||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#check-validity-steps | |||
WebIDL::ExceptionOr<bool> FormAssociatedElement::check_validity() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be better to rename this method to check_validity_steps()
to avoid the method being hidden. This would also match the name used in the spec.
I don't think there's any need for this to return ExceptionOr
since there's no way it can error.
This PR implements some core parts of the HTML “constraint-validation API” (aka “client-side form validation”):
form
element itself: theHTMLFormElement::checkValidity
methodcheckValidity
method for individual form controlsThe PR also implements all “suffering from being missing” constraints for
HTMLInputElement
.This change gets us a number of new passes for some of the 130 subtests of the test at https://wpt.fyi/results/html/semantics/forms/constraints/form-validation-checkValidity.html?product=ladybird. We should be able to get to passing 100% of those subtests in subsequent PRs that fill out the remaining constraint checks from that spec (and that are already stubbed out in the code, from a previous PR).