Permalink
Browse files

Fixed issue 78. Error/Valid styling applies to all radio buttons of s…

…ame group for required validation.
  • Loading branch information...
1 parent 3a42224 commit 393ccabc0786f70d3461df30195544d1a0904218 @Haacked Haacked committed with jzaefferer May 5, 2011
Showing with 34 additions and 4 deletions.
  1. +12 −4 jquery.validate.js
  2. +5 −0 test/index.html
  3. +17 −0 test/test.js
View
@@ -238,11 +238,19 @@ $.extend($.validator, {
else if (element.parentNode.name in this.submitted)
this.element(element.parentNode);
},
- highlight: function( element, errorClass, validClass ) {
- $(element).addClass(errorClass).removeClass(validClass);
+ highlight: function(element, errorClass, validClass) {
+ if (element.type === 'radio') {
+ this.findByName(element.name).addClass(errorClass).removeClass(validClass);
+ } else {
+ $(element).addClass(errorClass).removeClass(validClass);
+ }
},
- unhighlight: function( element, errorClass, validClass ) {
- $(element).removeClass(errorClass).addClass(validClass);
+ unhighlight: function(element, errorClass, validClass) {
+ if (element.type === 'radio') {
+ this.findByName(element.name).removeClass(errorClass).addClass(validClass);
+ } else {
+ $(element).removeClass(errorClass).addClass(validClass);
+ }
}
},
View
@@ -139,6 +139,11 @@ <h2 id="qunit-userAgent"></h2>
<input id="testEmail9" class="{required:true,email:true,messages:{required:'required',email:'email'}}" />
</form>
+ <form id="testForm10">
+ <input type="radio" name="testForm10Radio" value="1" id="testForm10Radio1" />
+ <input type="radio" name="testForm10Radio" value="2" id="testForm10Radio2" />
+ </form>
+
<div id="simplecontainer">
<h3></h3>
</div>
View
@@ -124,6 +124,23 @@ test("form(): checkboxes: min/required", function() {
$('#form6check2').attr("checked", true);
ok( v.form(), 'Valid form' );
});
+
+test("form(): radio buttons: required", function () {
+ expect( 6 );
+ var form = $('#testForm10')[0];
+
+ var v = $(form).validate({ rules: { testForm10Radio: "required"} });
+ ok(!v.form(), 'Invalid Form');
+ equals($('#testForm10Radio1').attr('class'), 'error');
+ equals($('#testForm10Radio2').attr('class'), 'error');
+
+ $('#testForm10Radio2').attr("checked", true);
+ ok(v.form(), 'Valid form');
+
+ equals($('#testForm10Radio1').attr('class'), 'valid');
+ equals($('#testForm10Radio2').attr('class'), 'valid');
+});
+
test("form(): selects: min/required", function() {
expect( 3 );
var form = $('#testForm7')[0];

0 comments on commit 393ccab

Please sign in to comment.