Skip to content

Commit caf8240

Browse files
committed
AC-10826 :: Storefront Bundle Checkbox Validation Error message count more than 1
1 parent 1bba929 commit caf8240

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

lib/web/jquery/jquery.validate.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
// Check if a validator for this form was already created
3333
var validator = $.data( this[ 0 ], "validator" );
34+
3435
if ( validator ) {
3536
return validator;
3637
}
@@ -235,6 +236,7 @@
235236
// https://jqueryvalidation.org/filled-selector/
236237
filled: function( a ) {
237238
var val = $( a ).val();
239+
238240
return val !== null && !!trim( "" + val );
239241
},
240242

@@ -256,6 +258,7 @@
256258
if ( arguments.length === 1 ) {
257259
return function() {
258260
var args = $.makeArray( arguments );
261+
259262
args.unshift( source );
260263
return $.validator.format.apply( this, args );
261264
};
@@ -406,6 +409,7 @@
406409
var currentForm = this.currentForm,
407410
groups = this.groups = {},
408411
rules;
412+
409413
$.each( this.settings.groups, function( key, value ) {
410414
if ( typeof value === "string" ) {
411415
value = value.split( /\s/ );
@@ -420,7 +424,8 @@
420424
} );
421425

422426
function delegate( event ) {
423-
var isContentEditable = typeof $( this ).attr( "contenteditable" ) !== "undefined" && $( this ).attr( "contenteditable" ) !== "false";
427+
var isContentEditable = typeof $( this ).attr( "contenteditable" ) !== "undefined"
428+
&& $( this ).attr( "contenteditable" ) !== "false";
424429

425430
// Set form expando on contenteditable
426431
if ( !this.form && isContentEditable ) {
@@ -437,6 +442,7 @@
437442
var validator = $.data( this.form, "validator" ),
438443
eventType = "on" + event.type.replace( /^validate/, "" ),
439444
settings = validator.settings;
445+
440446
if ( settings[ eventType ] && !$( this ).is( settings.ignore ) ) {
441447
settings[ eventType ].call( validator, this, event );
442448
}
@@ -477,13 +483,13 @@
477483
if ($(this.currentForm).find('.bundle').length > 0
478484
&& $(this.currentForm).find('input[type="checkbox"]').length > 0) {
479485
return this.checkBundleForm();
480-
} else {
481-
return this.checkDefaultForm();
482486
}
487+
return this.checkDefaultForm();
483488
},
484489

485490
checkBundleForm: function() {
486-
var group, optionNumber, elements, optionMap, el, option;
491+
var optionNumber, elements, optionMap, el, option;
492+
487493
this.prepareForm();
488494
elements = this.elements();
489495
optionMap = {};
@@ -502,11 +508,13 @@
502508
}
503509
return this.valid();
504510
},
511+
505512
processOptionGroup: function(group) {
506513
if (group.length > 0) {
507514
this.check(group[0]);
508515
}
509516
},
517+
510518
checkDefaultForm: function() {
511519
this.prepareForm();
512520
for (var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++) {
@@ -632,6 +640,7 @@
632640
/* jshint unused: false */
633641
var count = 0,
634642
i;
643+
635644
for ( i in obj ) {
636645

637646
// This check allows counting elements with empty error
@@ -678,6 +687,7 @@
678687

679688
findLastActive: function() {
680689
var lastActive = this.lastActive;
690+
681691
return lastActive && $.grep( this.errorList, function( n ) {
682692
return n.element.name === lastActive.name;
683693
} ).length === 1 && lastActive;
@@ -694,7 +704,9 @@
694704
.not( this.settings.ignore )
695705
.filter( function() {
696706
var name = this.name || $( this ).attr( "name" ); // For contenteditable
697-
var isContentEditable = typeof $( this ).attr( "contenteditable" ) !== "undefined" && $( this ).attr( "contenteditable" ) !== "false";
707+
708+
var isContentEditable = typeof $( this ).attr( "contenteditable" ) !== "undefined"
709+
&& $( this ).attr( "contenteditable" ) !== "false";
698710

699711
if ( !name && validator.settings.debug && window.console ) {
700712
console.error( "%o has no name assigned", this );
@@ -727,6 +739,7 @@
727739

728740
errors: function() {
729741
var errorClass = this.settings.errorClass.split( " " ).join( "." );
742+
730743
return $( this.settings.errorElement + "." + errorClass, this.errorContext );
731744
},
732745

@@ -883,6 +896,7 @@
883896
// Return the custom message for the given element name and validation method
884897
customMessage: function( name, method ) {
885898
var m = this.settings.messages[ name ];
899+
886900
return m && ( m.constructor === String ? m : m[ method ] );
887901
},
888902

@@ -951,6 +965,7 @@
951965

952966
defaultShowErrors: function() {
953967
var i, elements, error;
968+
954969
for ( i = 0; this.errorList[ i ]; i++ ) {
955970
error = this.errorList[ i ];
956971
if ( this.settings.highlight ) {
@@ -1148,6 +1163,7 @@
11481163

11491164
optional: function( element ) {
11501165
var val = this.elementValue( element );
1166+
11511167
return !$.validator.methods.required.call( this, val, element ) && "dependency-mismatch";
11521168
},
11531169

@@ -1319,6 +1335,7 @@
13191335
}
13201336

13211337
var meta = $.data(element.form, 'validator').settings.meta;
1338+
13221339
return meta ?
13231340
$(element).metadata()[meta] :
13241341
$(element).metadata();
@@ -1364,6 +1381,7 @@
13641381
}
13651382
if ( val.param || val.depends ) {
13661383
var keepRule = true;
1384+
13671385
switch ( typeof val.depends ) {
13681386
case "string":
13691387
keepRule = !!$( val.depends, element.form ).length;
@@ -1375,7 +1393,7 @@
13751393
if ( keepRule ) {
13761394
rules[ prop ] = val.param !== undefined ? val.param : true;
13771395
} else {
1378-
$.data( element.form, "validator" ).resetElements( $( element ) );
1396+
$.data(element.form, "validator").resetElements($(element));
13791397
delete rules[ prop ];
13801398
}
13811399
}
@@ -1394,6 +1412,7 @@
13941412
} );
13951413
$.each( [ "rangelength", "range" ], function() {
13961414
var parts;
1415+
13971416
if ( rules[ this ] ) {
13981417
if ( Array.isArray( rules[ this ] ) ) {
13991418
rules[ this ] = [ Number( rules[ this ][ 0 ] ), Number( rules[ this ][ 1 ] ) ];
@@ -1426,6 +1445,7 @@
14261445
normalizeRule: function( data ) {
14271446
if ( typeof data === "string" ) {
14281447
var transformed = {};
1448+
14291449
$.each( data.split( /\s/ ), function() {
14301450
transformed[ this ] = true;
14311451
} );
@@ -1457,6 +1477,7 @@
14571477

14581478
// Could be an array for select-multiple or a string, both are fine this way
14591479
var val = $( element ).val();
1480+
14601481
return val && val.length > 0;
14611482
}
14621483
if ( this.checkable( element ) ) {
@@ -1578,8 +1599,7 @@
15781599
toInt = function( num ) {
15791600
return Math.round( num * Math.pow( 10, decimals ) );
15801601
},
1581-
valid = true,
1582-
decimals;
1602+
valid = true;
15831603

15841604
// Works only for text, number and range input types
15851605
// TODO find a way to support input types date, datetime, datetime-local, month, time and week
@@ -1602,6 +1622,7 @@
16021622

16031623
// Bind to the blur event of the target in order to revalidate whenever the target field is updated
16041624
var target = $( param );
1625+
16051626
if ( this.settings.onfocusout && target.not( ".validate-equalTo-blur" ).length ) {
16061627
target.addClass( "validate-equalTo-blur" ).on( "blur.validate-equalTo", function() {
16071628
$( element ).valid();

0 commit comments

Comments
 (0)