mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 20:29:18 +00:00
LibWeb: Implement HTMLFormElement::checkValidity (constraint validation)
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.
This commit is contained in:
parent
b4e47f198a
commit
7c34746571
Notes:
github-actions[bot]
2025-02-26 04:14:35 +00:00
Author: https://github.com/sideshowbarker
Commit: 7c34746571
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3674
Reviewed-by: https://github.com/tcl3 ✅
4 changed files with 62 additions and 2 deletions
|
@ -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
|
||||
bool FormAssociatedElement::check_validity_steps()
|
||||
{
|
||||
// 1. If element is a candidate for constraint validation and does not satisfy its constraints
|
||||
if (is_candidate_for_constraint_validation() && !satisfies_its_constraints()) {
|
||||
auto& element = form_associated_element_to_html_element();
|
||||
// 1. Fire an event named invalid at element, with the cancelable attribute initialized to true
|
||||
element.dispatch_event(DOM::Event::create(element.realm(), EventNames::invalid, { .cancelable = true }));
|
||||
// 2. Return false.
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#candidate-for-constraint-validation
|
||||
bool FormAssociatedElement::is_candidate_for_constraint_validation() const
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue