mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
LibWeb: Validate form submissions whose submitter is not form-associated
The spec for checking the no-validate state ends with a default return value of "false". However, we were only hitting this case for form- associated elements. If the submitter is the form itself, we want to enter the form validation steps.
This commit is contained in:
parent
23aadc02ca
commit
017ae80668
|
|
@ -96,6 +96,16 @@ WebIDL::ExceptionOr<void> HTMLFormElement::implicitly_submit_form()
|
|||
return {};
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fs-novalidate
|
||||
static bool novalidate_state(HTMLElement const& element)
|
||||
{
|
||||
// The no-validate state of an element is true if the element is a submit button and the element's formnovalidate
|
||||
// attribute is present, or if the element's form owner's novalidate attribute is present, and false otherwise.
|
||||
if (auto const* form_associated_element = as_if<FormAssociatedElement>(element))
|
||||
return form_associated_element->novalidate_state();
|
||||
return false;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-form-submit
|
||||
WebIDL::ExceptionOr<void> HTMLFormElement::submit_form(GC::Ref<HTMLElement> submitter, SubmitFormOptions options)
|
||||
{
|
||||
|
|
@ -142,8 +152,7 @@ WebIDL::ExceptionOr<void> HTMLFormElement::submit_form(GC::Ref<HTMLElement> subm
|
|||
// 4. If the submitter element's no-validate state is false, then interactively validate the constraints
|
||||
// of form and examine the result. If the result is negative (i.e., the constraint validation concluded
|
||||
// that there were invalid fields and probably informed the user of this), then:
|
||||
auto* form_associated_element = as_if<FormAssociatedElement>(*submitter);
|
||||
if (form_associated_element && !form_associated_element->novalidate_state()) {
|
||||
if (!novalidate_state(submitter)) {
|
||||
auto validation_result = interactively_validate_constraints();
|
||||
if (!validation_result) {
|
||||
// 1. Set form's firing submission events to false.
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ Harness status: OK
|
|||
|
||||
Found 2 tests
|
||||
|
||||
2 Fail
|
||||
1 Pass
|
||||
1 Fail
|
||||
Fail Validation for placeholder option
|
||||
Fail Check form not submitted for invalid select
|
||||
Pass Check form not submitted for invalid select
|
||||
Loading…
Reference in New Issue
Block a user