Skip to content

Commit f0b8042

Browse files
committed
resetForm now clears old previousValue on form elements. Fixes jquery-validation#312
1 parent c3ce5b4 commit f0b8042

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

jquery.validate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ $.extend($.validator, {
410410
this.lastElement = null;
411411
this.prepareForm();
412412
this.hideErrors();
413-
this.elements().removeClass( this.settings.errorClass );
413+
this.elements().removeClass( this.settings.errorClass ).removeData( "previousValue" );
414414
},
415415

416416
numberOfInvalids: function() {

test/methods.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -495,16 +495,16 @@ asyncTest("remote radio correct value sent", function() {
495495
v.element(e);
496496
});
497497

498-
asyncTest("remote correct number of invalids", function() {
499-
expect(4);
498+
asyncTest("remote reset clear old value", function() {
499+
expect(1);
500+
500501
var e = $("#username");
501502
var v = $("#userForm").validate({
502503
rules: {
503504
username: {
504505
required: true,
505506
remote: {
506507
url: "echo.php",
507-
dataType: 'json',
508508
dataFilter: function(data) {
509509
var json = JSON.parse(data);
510510
if(json.username == 'asdf') {
@@ -514,33 +514,31 @@ asyncTest("remote correct number of invalids", function() {
514514
}
515515
}
516516
}
517-
},
518-
messages: {
519-
username: {
520-
required: "Please"
521-
}
522-
},
523-
submitHandler: function() {
524-
ok( false, "submitHandler may never be called when validating only elements");
525517
}
526518
});
527519
$(document).ajaxStop(function() {
520+
var waitTimeout;
521+
528522
$(document).unbind("ajaxStop");
529-
equal( 1, v.numberOfInvalids(), "There must be one error" );
530523

531-
e.val("max");
532524

533525
$(document).ajaxStop(function() {
534-
equal( 0, v.numberOfInvalids(), "There must not be any errors" );
526+
clearTimeout(waitTimeout);
527+
ok( true, "Remote request sent to server" );
535528
start();
536529
});
537530

531+
532+
v.resetForm();
533+
e.val("asdf");
534+
waitTimeout = setTimeout(function() {
535+
ok( false, "Remote server did not get request");
536+
start();
537+
}, 200);
538538
v.element(e);
539539
});
540-
strictEqual( v.element(e), false, "invalid element, nothing entered yet" );
541540
e.val("asdf");
542-
strictEqual( v.numberOfInvalids(), 1, "still invalid, because remote validation must block until it returns; dependency-mismatch considered as valid though" );
543-
v.element(e);
541+
v.element(e);
544542
});
545543

546544
module("additional methods");

test/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ $.mockjax({
2626
url: "echo.php",
2727
response: function(data) {
2828
this.responseText = JSON.stringify(data.data);
29-
}
29+
},
30+
responseTime: 100
3031
});
3132

3233
module("validator");

0 commit comments

Comments
 (0)