Closed
Bug 1100535
Opened 10 years ago
Closed 10 years ago
HTML 5 Required Validation on radio button does not clear when reset (33.1)
Categories
(Core :: DOM: Core & HTML, defect)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
mozilla36
People
(Reporter: JASON.FINCH, Assigned: agi)
Details
(Keywords: reproducible, testcase)
Attachments
(2 files, 2 obsolete files)
390 bytes,
text/html
|
Details | |
10.75 KB,
patch
|
Details | Diff | Splinter Review |
User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0
Build ID: 20141106120505
Steps to reproduce:
Firefox 33.1/Windows, when using Angular 1.2.26 to enable/disable 'Required' attribute on a radio button set, the radio buttons will change their state to required and show the HTML5 validation as expected. But then if they are toggled/alterted to remove 'required' the state still retains the 'required' functionality.
In Chrome/Win, this issue is not experienced using the same plnkr example.
Ref:
https://github.com/angular/angular.js/issues/10089#issuecomment-63296014
Repro here: http://plnkr.co/edit/tBlM5KXb5DLP1Hb8ta8U?p=preview
Actual results:
Radio buttons continue to act as if 'required' is still active by showing the HTML5 validation warning popups.
Expected results:
When the radio buttons 'required' is toggled off the HTML5 validation should not continue to engage.
Updated•10 years ago
|
Status: UNCONFIRMED → NEW
Component: Untriaged → DOM: Core & HTML
Ever confirmed: true
Keywords: reproducible,
testcase
OS: Windows 7 → All
Product: Firefox → Core
Hardware: x86_64 → All
Comment 2•10 years ago
|
||
This needs a somewhat minimized testcase. A basic testcase like this:
<style>
input:invalid { outline: 5px solid red; }
</style>
<form>
<input type="radio" required name="a">
<input type="radio" required name="a">
</form>
<script>
document.writeln(document.forms[0].checkValidity());
var inputs = document.querySelectorAll("input");
Array.prototype.forEach.call(inputs, function(input) { input.required = false; });
document.writeln(document.forms[0].checkValidity());
</script>
works fine....
Comment 3•10 years ago
|
||
Oh, this is exciting. We get JS code that does this:
element[name] = value;
where name == "required" and value = true. This calls SetRequired, which internally calls setAttribute("required", "").
Then we get more JS code doing this:
element[name] = true;
element.setAttribute(name, lowercasedName);
(why, who knows). That first set is a no-op, but the second changes the attr value from "" to "required".
This triggers a bug in HTMLInputElement::AfterSetAttr where we do:
1408 if (mType == NS_FORM_INPUT_RADIO && aName == nsGkAtoms::required) {
1409 nsCOMPtr<nsIRadioGroupContainer> container = GetRadioGroupContainer();
1410
1411 if (container) {
1412 nsAutoString name;
1413 GetAttr(kNameSpaceID_None, nsGkAtoms::name, name);
1414 container->RadioRequiredChanged(name, this);
1415 }
1416 }
and RadioRequiredChanged actually assumes that the state changed. But in this case the state did NOT change, since we went from one truthy value to another. So we end up thinking we have 4 required radios in the group, then remove two of them when required is toggled to false, but still think we have two required radios in there.
Olli, do you have time to look into this one?
Flags: needinfo?(bugs)
Comment 4•10 years ago
|
||
Assignee | ||
Comment 5•10 years ago
|
||
(sorry for the delay, my dev pc died a few days ago)
Maybe we can move the RadioRequiredChanged to BeforeSetAttr and only call it if the value actually changed?
Flags: needinfo?(agi.novanta)
Comment 6•10 years ago
|
||
RadioRequiredChanged unfortunately examines the value of the attr to figure out what it changed to. Though we could change that and pass in the value, I guess. Worth trying.
Comment 7•10 years ago
|
||
comment 5 is probably the simplest approach (+ adding needed params to RadioRequiredChanged).
agi, want to look at this?
Flags: needinfo?(bugs)
Updated•10 years ago
|
Flags: needinfo?(agi.novanta)
Assignee | ||
Comment 8•10 years ago
|
||
Yup. I'll post a patch probably tonight.
Flags: needinfo?(agi.novanta)
Assignee | ||
Updated•10 years ago
|
Version: 33 Branch → Trunk
Assignee | ||
Comment 9•10 years ago
|
||
This should do. Thanks bz for the investigation & the testcase! :-)
Attachment #8527335 -
Attachment is obsolete: true
Attachment #8529431 -
Flags: review?(bugs)
Comment 10•10 years ago
|
||
Comment on attachment 8529431 [details] [diff] [review]
Do not assume that the radio required status changed when the attribute changes.
Maybe s/aNewValue/aRequiredAdded/ ?
Attachment #8529431 -
Flags: review?(bugs) → review+
Assignee | ||
Comment 11•10 years ago
|
||
> Maybe s/aNewValue/aRequiredAdded/ ?
Done! Thanks Olli!
try:
https://treeherder.mozilla.org/ui/#/jobs?repo=try&revision=459359866650
https://tbpl.mozilla.org/?tree=Try&rev=459359866650
Assignee: nobody → agi.novanta
Attachment #8529431 -
Attachment is obsolete: true
Assignee | ||
Updated•10 years ago
|
Flags: in-testsuite+
Keywords: checkin-needed
Comment 12•10 years ago
|
||
Keywords: checkin-needed
Comment 13•10 years ago
|
||
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla36
You need to log in
before you can comment on or make changes to this bug.
Description
•