File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -1159,9 +1159,12 @@ $.extend($.validator, {
1159
1159
equalTo : function ( value , element , param ) {
1160
1160
// bind to the blur event of the target in order to revalidate whenever the target field is updated
1161
1161
// 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
+ }
1165
1168
return value === target . val ( ) ;
1166
1169
}
1167
1170
Original file line number Diff line number Diff line change @@ -167,6 +167,23 @@ test("form(): with equalTo", function() {
167
167
ok ( v . form ( ) , 'Valid form' ) ;
168
168
} ) ;
169
169
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
+
170
187
test ( "check(): simple" , function ( ) {
171
188
expect ( 3 ) ;
172
189
var element = $ ( '#firstname' ) [ 0 ] ;
You can’t perform that action at this time.
0 commit comments