Skip to content

Commit 1bba929

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

File tree

1 file changed

+48
-31
lines changed

1 file changed

+48
-31
lines changed

lib/web/jquery/jquery.validate.js

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@
404404
this.reset();
405405

406406
var currentForm = this.currentForm,
407-
groups = ( this.groups = {} ),
407+
groups = this.groups = {},
408408
rules;
409409
$.each( this.settings.groups, function( key, value ) {
410410
if ( typeof value === "string" ) {
@@ -444,9 +444,12 @@
444444

445445
$( this.currentForm )
446446
.on( "focusin.validate focusout.validate keyup.validate",
447-
":text, [type='password'], [type='file'], select, textarea, [type='number'], [type='search'], " +
448-
"[type='tel'], [type='url'], [type='email'], [type='datetime'], [type='date'], [type='month'], " +
449-
"[type='week'], [type='time'], [type='datetime-local'], [type='range'], [type='color'], " +
447+
":text, [type='password'], [type='file'], " +
448+
"select, textarea, [type='number'], [type='search'], " +
449+
"[type='tel'], [type='url'], [type='email'], " +
450+
"[type='datetime'], [type='date'], [type='month'], " +
451+
"[type='week'], [type='time'], [type='datetime-local'], " +
452+
"[type='range'], [type='color'], " +
450453
"[type='radio'], [type='checkbox'], [contenteditable], [type='button']", delegate )
451454

452455
// Support: Chrome, oldIE
@@ -471,34 +474,45 @@
471474
},
472475

473476
checkForm: function() {
474-
if ($(this.currentForm).find('.bundle').length > 0) {
475-
this.prepareForm();
476-
var elements = this.elements();
477-
var optionMap = {};
478-
for (var i = 0; i < elements.length; i++) {
479-
var el = elements[i];
480-
var optionNumber = el.id.split('-')[2];
481-
if (!optionMap[optionNumber]) {
482-
optionMap[optionNumber] = [];
483-
}
484-
optionMap[optionNumber].push(el);
485-
}
486-
for (var option in optionMap) {
487-
if (optionMap.hasOwnProperty(option)) {
488-
var group = optionMap[option];
489-
if (group.length > 0) {
490-
this.check(group[0]);
491-
}
492-
}
493-
}
494-
return this.valid();
477+
if ($(this.currentForm).find('.bundle').length > 0
478+
&& $(this.currentForm).find('input[type="checkbox"]').length > 0) {
479+
return this.checkBundleForm();
495480
} else {
496-
this.prepareForm();
497-
for ( var i = 0, elements = ( this.currentElements = this.elements() ); elements[ i ]; i++ ) {
498-
this.check( elements[ i ] );
481+
return this.checkDefaultForm();
482+
}
483+
},
484+
485+
checkBundleForm: function() {
486+
var group, optionNumber, elements, optionMap, el, option;
487+
this.prepareForm();
488+
elements = this.elements();
489+
optionMap = {};
490+
for (var i = 0; i < elements.length; i++) {
491+
el = elements[i];
492+
optionNumber = el.id.split('-')[2];
493+
if (!optionMap[optionNumber]) {
494+
optionMap[optionNumber] = [];
495+
}
496+
optionMap[optionNumber].push(el);
497+
}
498+
for (option in optionMap) {
499+
if (optionMap.hasOwnProperty(option)) {
500+
this.processOptionGroup(optionMap[option]);
499501
}
500-
return this.valid();
501502
}
503+
return this.valid();
504+
},
505+
processOptionGroup: function(group) {
506+
if (group.length > 0) {
507+
this.check(group[0]);
508+
}
509+
},
510+
checkDefaultForm: function() {
511+
this.prepareForm();
512+
for (var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++) {
513+
this.check(elements[i]);
514+
}
515+
return this.valid();
502516
},
503517

504518
// https://jqueryvalidation.org/Validator.element/
@@ -1309,7 +1323,6 @@
13091323
$(element).metadata()[meta] :
13101324
$(element).metadata();
13111325
},
1312-
13131326
dataRules: function( element ) {
13141327
var rules = {},
13151328
$element = $( element ),
@@ -1512,18 +1525,21 @@
15121525
// https://jqueryvalidation.org/minlength-method/
15131526
minlength: function( value, element, param ) {
15141527
var length = Array.isArray( value ) ? value.length : this.getLength( value, element );
1528+
15151529
return this.optional( element ) || length >= param;
15161530
},
15171531

15181532
// https://jqueryvalidation.org/maxlength-method/
15191533
maxlength: function( value, element, param ) {
15201534
var length = Array.isArray( value ) ? value.length : this.getLength( value, element );
1535+
15211536
return this.optional( element ) || length <= param;
15221537
},
15231538

15241539
// https://jqueryvalidation.org/rangelength-method/
15251540
rangelength: function( value, element, param ) {
15261541
var length = Array.isArray( value ) ? value.length : this.getLength( value, element );
1542+
15271543
return this.optional( element ) || ( length >= param[ 0 ] && length <= param[ 1 ] );
15281544
},
15291545

@@ -1558,6 +1574,7 @@
15581574
// Number of digits right of decimal point.
15591575
return match[ 1 ] ? match[ 1 ].length : 0;
15601576
},
1577+
decimals = 0,
15611578
toInt = function( num ) {
15621579
return Math.round( num * Math.pow( 10, decimals ) );
15631580
},
@@ -1628,7 +1645,7 @@
16281645
data: data,
16291646
context: validator.currentForm,
16301647
success: function( response ) {
1631-
var valid = response === true || response === "true",
1648+
var valid = response === true || response === 'true',
16321649
errors, message, submitted;
16331650

16341651
validator.settings.messages[ element.name ][ method ] = previous.originalMessage;

0 commit comments

Comments
 (0)