Bug 1795887 - Fix IsValueMissing update for certain input types. r=edgar

Differential Revision: https://phabricator.services.mozilla.com/D159592
This commit is contained in:
Adam Vandolder
2022-10-22 16:34:48 +00:00
parent 541ba1b114
commit 357062f28e
12 changed files with 18 additions and 46 deletions

View File

@@ -6508,25 +6508,26 @@ void HTMLInputElement::UpdateValueMissingValidityStateForRadio(
HTMLInputElement* selection = GetSelectedRadioButton();
aIgnoreSelf = aIgnoreSelf || !IsMutable();
// If there is no selection, that might mean the radio is not in a group.
// In that case, we can look for the checked state of the radio.
bool selected = selection || (!aIgnoreSelf && mChecked);
bool required = !aIgnoreSelf && IsRequired();
bool valueMissing = false;
nsCOMPtr<nsIRadioGroupContainer> container = GetRadioGroupContainer();
if (!container) {
SetValidityState(VALIDITY_STATE_VALUE_MISSING,
IsMutable() && required && !selected);
return;
}
nsAutoString name;
GetAttr(kNameSpaceID_None, nsGkAtoms::name, name);
if (!container) {
// As per the spec, a radio button not within a radio button group cannot
// suffer from being missing; however, we currently are failing to get a
// radio group in the case of a single, named radio button that has no
// form owner, forcing us to check for validity in that case here.
SetValidityState(VALIDITY_STATE_VALUE_MISSING,
required && !selected && !name.IsEmpty());
return;
}
// If the current radio is required and not ignored, we can assume the entire
// group is required.
if (!required) {
@@ -6535,8 +6536,7 @@ void HTMLInputElement::UpdateValueMissingValidityStateForRadio(
: container->GetRequiredRadioCount(name);
}
valueMissing = required && !selected;
bool valueMissing = required && !selected;
if (container->GetValueMissingState(name) != valueMissing) {
container->SetValueMissingState(name, valueMissing);