Bug 982039 - Radio input required not working when element disabled by js, r=bz
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Thu, 10 Jul 2014 18:01:59 +0300
changeset 214190 7d69a8da6ce30eb92f5f7279dddc9b7321050a34
parent 214189 d6a41b0f97945fa5881cc2a269ec1779241d96c2
child 214191 c57055b25e808979a2662e0cdc04a654494b92ed
push id3857
push userraliiev@mozilla.com
push dateTue, 02 Sep 2014 16:39:23 +0000
treeherdermozilla-beta@5638b907b505 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs982039
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 982039 - Radio input required not working when element disabled by js, r=bz
content/html/content/src/HTMLInputElement.cpp
content/html/content/test/mochitest.ini
content/html/content/test/test_bug982039.html
--- a/content/html/content/src/HTMLInputElement.cpp
+++ b/content/html/content/src/HTMLInputElement.cpp
@@ -6594,16 +6594,18 @@ HTMLInputElement::UpdateTooLongValidityS
 }
 
 void
 HTMLInputElement::UpdateValueMissingValidityStateForRadio(bool aIgnoreSelf)
 {
   bool notify = !mParserCreating;
   nsCOMPtr<nsIDOMHTMLInputElement> 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 && HasAttr(kNameSpaceID_None, nsGkAtoms::required);
   bool valueMissing = false;
 
   nsCOMPtr<nsIRadioGroupContainer> container = GetRadioGroupContainer();
 
@@ -6619,17 +6621,17 @@ HTMLInputElement::UpdateValueMissingVali
   // If the current radio is required and not ignored, we can assume the entire
   // group is required.
   if (!required) {
     required = (aIgnoreSelf && HasAttr(kNameSpaceID_None, nsGkAtoms::required))
                  ? container->GetRequiredRadioCount(name) - 1
                  : container->GetRequiredRadioCount(name);
   }
 
-  valueMissing = IsMutable() && required && !selected;
+  valueMissing = required && !selected;
 
   if (container->GetValueMissingState(name) != valueMissing) {
     container->SetValueMissingState(name, valueMissing);
 
     SetValidityState(VALIDITY_STATE_VALUE_MISSING, valueMissing);
 
     // nsRadioSetValueMissingState will call ContentStateChanged while visiting.
     nsAutoScriptBlocker scriptBlocker;
--- a/content/html/content/test/mochitest.ini
+++ b/content/html/content/test/mochitest.ini
@@ -409,16 +409,17 @@ skip-if = (toolkit == 'gonk' && debug) |
 [test_bug845057.html]
 [test_bug869040.html]
 [test_bug870787.html]
 [test_bug874758.html]
 [test_bug879319.html]
 [test_bug885024.html]
 [test_bug893537.html]
 [test_bug969346.html]
+[test_bug982039.html]
 [test_bug1003539.html]
 [test_change_crossorigin.html]
 [test_checked.html]
 [test_dir_attributes_reflection.html]
 [test_dl_attributes_reflection.html]
 [test_element_prototype.html]
 [test_embed_attributes_reflection.html]
 [test_formData.html]
new file mode 100644
--- /dev/null
+++ b/content/html/content/test/test_bug982039.html
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=982039
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 982039</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript">
+
+  /** Test for Bug 982039 **/
+  SimpleTest.waitForExplicitFinish();
+  function test() {
+    var f = document.getElementById("testform");
+    f.elements[0].disabled = true;
+    is(f.checkValidity(), false,
+       "Setting a radiobutton to disabled shouldn't make form valid.");
+
+    f.elements[1].checked = true;
+    ok(f.checkValidity(), "Form should be now valid.");
+
+    f.elements[0].required = false;
+    f.elements[1].required = false;
+    f.elements[2].required = false;
+    SimpleTest.finish();
+  }
+
+  </script>
+</head>
+<body onload="test()">
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=982039">Mozilla Bug 982039</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+<form action="#" id="testform">
+  <input type="radio" name="radio" value="1" required>
+  <input type="radio" name="radio" value="2" required>
+  <input type="radio" name="radio" value="3" required>
+</form>
+</body>
+</html>