Skip to content

Commit aca144b

Browse files
mlynchjzaefferer
authored andcommitted
Disables blur event when onfocusout is set to false. Test added.
1 parent 5893087 commit aca144b

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

jquery.validate.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,9 +1159,12 @@ $.extend($.validator, {
11591159
equalTo: function(value, element, param) {
11601160
// bind to the blur event of the target in order to revalidate whenever the target field is updated
11611161
// TODO find a way to bind the event just once, avoiding the unbind-rebind overhead
1162-
var target = $(param).unbind(".validate-equalTo").bind("blur.validate-equalTo", function() {
1163-
$(element).valid();
1164-
});
1162+
var target = $(param);
1163+
if (this.settings.onfocusout) {
1164+
target.unbind(".validate-equalTo").bind("blur.validate-equalTo", function() {
1165+
$(element).valid();
1166+
});
1167+
}
11651168
return value === target.val();
11661169
}
11671170

test/test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,23 @@ test("form(): with equalTo", function() {
167167
ok( v.form(), 'Valid form' );
168168
});
169169

170+
test("form(): with equalTo and onfocusout=false", function() {
171+
expect( 4 );
172+
var form = $('#testForm5')[0];
173+
var v = $(form).validate({
174+
onfocusout: false,
175+
showErrors: function() {
176+
ok(true, 'showErrors should only be called twice');
177+
this.defaultShowErrors();
178+
}
179+
});
180+
$('#x1, #x2').val("hi");
181+
ok( v.form(), 'Valid form' );
182+
$('#x2').val('not equal').blur();
183+
ok( !v.form(), 'Invalid form' );
184+
});
185+
186+
170187
test("check(): simple", function() {
171188
expect( 3 );
172189
var element = $('#firstname')[0];

0 commit comments

Comments
 (0)