Skip to content

Fixed value issue for radio buttons and checkboxes. Fixes #363 #368

Closed
wants to merge 3 commits into from
View
10 jquery.validate.js
@@ -510,8 +510,14 @@ $.extend($.validator, {
},
elementValue: function( element ) {
- var val = $(element).val();
- if( typeof val === 'string' ) {
+ var type = $(element).attr('type'),
+ val = $(element).val();
+
+ if ( type === 'radio' || type === 'checkbox' ) {
+ return $('input[name="' + $(element).attr('name') + '"]:checked').val();
+ }
+
+ if ( typeof val === 'string' ) {
return val.replace(/\r/g, "");
}
return val;
View
23 test/methods.js
@@ -472,6 +472,29 @@ test("remote extensions", function() {
strictEqual( v.element(e), true, "still invalid, because remote validation must block until it returns; dependency-mismatch considered as valid though" );
});
+asyncTest("remote radio correct value sent", function() {
+ expect(1);
+ var e = $("#testForm10Radio2");
+ e.attr('checked', 'checked');
+ var v = $("#testForm10").validate({
+ rules: {
+ testForm10Radio: {
+ required: true,
+ remote: {
+ url: "echo.php",
+ dataType: "json",
+ success: function(data) {
+ equal( data['testForm10Radio'], '2', ' correct radio value sent' );
+ start();
+ }
+ }
+ },
+ }
+ });
+
+ v.element(e);
+});
+
module("additional methods");
test("phone (us)", function() {
View
6 test/test.js
@@ -22,6 +22,12 @@ $.mockjax({
responseStatus: 200,
responseTime: 1
});
+$.mockjax({
+ url: "echo.php",
+ response: function(data) {
+ this.responseText = JSON.stringify(data.data);
+ }
+});
module("validator");
Something went wrong with that request. Please try again.