Fixed invalid count on invalid to valid remote validation. Fixes #286

This commit is contained in:
Max Lynch
2012-04-24 13:39:19 -05:00
committed by Jörn Zaefferer
parent f037939682
commit 7cc01adbd1
2 changed files with 50 additions and 0 deletions

View File

@@ -495,6 +495,54 @@ asyncTest("remote radio correct value sent", function() {
v.element(e);
});
asyncTest("remote correct number of invalids", function() {
expect(4);
var e = $("#username");
var v = $("#userForm").validate({
rules: {
username: {
required: true,
remote: {
url: "echo.php",
dataType: 'json',
dataFilter: function(data) {
var json = JSON.parse(data);
if(json.username == 'asdf') {
return "\"asdf is already taken\"";
}
return true;
}
}
}
},
messages: {
username: {
required: "Please"
}
},
submitHandler: function() {
ok( false, "submitHandler may never be called when validating only elements");
}
});
$(document).ajaxStop(function() {
$(document).unbind("ajaxStop");
equal( 1, v.numberOfInvalids(), "There must be one error" );
e.val("max");
$(document).ajaxStop(function() {
equal( 0, v.numberOfInvalids(), "There must not be any errors" );
start();
});
v.element(e);
});
strictEqual( v.element(e), false, "invalid element, nothing entered yet" );
e.val("asdf");
strictEqual( v.numberOfInvalids(), 1, "still invalid, because remote validation must block until it returns; dependency-mismatch considered as valid though" );
v.element(e);
});
module("additional methods");
test("phone (us)", function() {