resetForm now clears old previousValue on form elements. Fixes #312

This commit is contained in:
Max Lynch
2012-05-04 10:48:49 -05:00
parent c3ce5b4569
commit f0b8042233
3 changed files with 19 additions and 20 deletions

2
jquery.validate.js vendored
View File

@@ -410,7 +410,7 @@ $.extend($.validator, {
this.lastElement = null; this.lastElement = null;
this.prepareForm(); this.prepareForm();
this.hideErrors(); this.hideErrors();
this.elements().removeClass( this.settings.errorClass ); this.elements().removeClass( this.settings.errorClass ).removeData( "previousValue" );
}, },
numberOfInvalids: function() { numberOfInvalids: function() {

View File

@@ -495,8 +495,9 @@ asyncTest("remote radio correct value sent", function() {
v.element(e); v.element(e);
}); });
asyncTest("remote correct number of invalids", function() { asyncTest("remote reset clear old value", function() {
expect(4); expect(1);
var e = $("#username"); var e = $("#username");
var v = $("#userForm").validate({ var v = $("#userForm").validate({
rules: { rules: {
@@ -504,7 +505,6 @@ asyncTest("remote correct number of invalids", function() {
required: true, required: true,
remote: { remote: {
url: "echo.php", url: "echo.php",
dataType: 'json',
dataFilter: function(data) { dataFilter: function(data) {
var json = JSON.parse(data); var json = JSON.parse(data);
if(json.username == 'asdf') { if(json.username == 'asdf') {
@@ -514,32 +514,30 @@ asyncTest("remote correct number of invalids", function() {
} }
} }
} }
},
messages: {
username: {
required: "Please"
}
},
submitHandler: function() {
ok( false, "submitHandler may never be called when validating only elements");
} }
}); });
$(document).ajaxStop(function() { $(document).ajaxStop(function() {
$(document).unbind("ajaxStop"); var waitTimeout;
equal( 1, v.numberOfInvalids(), "There must be one error" );
$(document).unbind("ajaxStop");
e.val("max");
$(document).ajaxStop(function() { $(document).ajaxStop(function() {
equal( 0, v.numberOfInvalids(), "There must not be any errors" ); clearTimeout(waitTimeout);
ok( true, "Remote request sent to server" );
start(); start();
}); });
v.resetForm();
e.val("asdf");
waitTimeout = setTimeout(function() {
ok( false, "Remote server did not get request");
start();
}, 200);
v.element(e); v.element(e);
}); });
strictEqual( v.element(e), false, "invalid element, nothing entered yet" );
e.val("asdf"); 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); v.element(e);
}); });

View File

@@ -26,7 +26,8 @@ $.mockjax({
url: "echo.php", url: "echo.php",
response: function(data) { response: function(data) {
this.responseText = JSON.stringify(data.data); this.responseText = JSON.stringify(data.data);
} },
responseTime: 100
}); });
module("validator"); module("validator");