Skip to content

Commit ed81e7d

Browse files
committed
AC-14403:: Investigate the latest version jquery-validate
1 parent 239d499 commit ed81e7d

File tree

2 files changed

+19
-27
lines changed

2 files changed

+19
-27
lines changed

lib/web/jquery/jquery.validate.js

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*!
2-
* jQuery Validation Plugin v1.20.0
2+
* jQuery Validation Plugin v1.21.0
33
*
44
* https://jqueryvalidation.org/
55
*
6-
* Copyright (c) 2023 Jörn Zaefferer
6+
* Copyright (c) 2024 Jörn Zaefferer
77
* Released under the MIT license
88
*/
99
(function( factory ) {
1010
if ( typeof define === "function" && define.amd ) {
11-
define( ["jquery", "jquery/jquery.metadata"], factory );
11+
define( ["jquery"], factory );
1212
} else if (typeof module === "object" && module.exports) {
1313
module.exports = factory( require( "jquery" ) );
1414
} else {
@@ -192,7 +192,6 @@
192192
data = $.validator.normalizeRules(
193193
$.extend(
194194
{},
195-
$.validator.metadataRules(element),
196195
$.validator.classRules( element ),
197196
$.validator.attributeRules( element ),
198197
$.validator.dataRules( element ),
@@ -294,6 +293,7 @@
294293
onsubmit: true,
295294
ignore: ":hidden",
296295
ignoreTitle: false,
296+
customElements: [],
297297
onfocusin: function( element ) {
298298
this.lastActive = element;
299299

@@ -441,17 +441,17 @@
441441
settings[ eventType ].call( validator, this, event );
442442
}
443443
}
444-
444+
var focusListeners = [ ":text", "[type='password']", "[type='file']", "select", "textarea", "[type='number']", "[type='search']",
445+
"[type='tel']", "[type='url']", "[type='email']", "[type='datetime']", "[type='date']", "[type='month']",
446+
"[type='week']", "[type='time']", "[type='datetime-local']", "[type='range']", "[type='color']",
447+
"[type='radio']", "[type='checkbox']", "[contenteditable]", "[type='button']" ];
448+
var clickListeners = [ "select", "option", "[type='radio']", "[type='checkbox']" ];
445449
$( this.currentForm )
446-
.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'], " +
450-
"[type='radio'], [type='checkbox'], [contenteditable], [type='button']", delegate )
450+
.on( "focusin.validate focusout.validate keyup.validate", focusListeners.concat( this.settings.customElements ).join( ", " ), delegate )
451451

452452
// Support: Chrome, oldIE
453453
// "select" is provided as event.target when clicking a option
454-
.on( "click.validate", "select, option, [type='radio'], [type='checkbox']", delegate );
454+
.on( "click.validate", clickListeners.concat( this.settings.customElements ).join( ", " ), delegate );
455455

456456
if ( this.settings.invalidHandler ) {
457457
$( this.currentForm ).on( "invalid-form.validate", this.settings.invalidHandler );
@@ -648,11 +648,12 @@
648648

649649
elements: function() {
650650
var validator = this,
651-
rulesCache = {};
651+
rulesCache = {},
652+
selectors = [ "input", "select", "textarea", "[contenteditable]" ];
652653

653654
// Select all valid inputs inside the form (no submit or reset buttons)
654655
return $( this.currentForm )
655-
.find( "input, select, textarea, [contenteditable]" )
656+
.find( selectors.concat( this.settings.customElements ).join( ", " ) )
656657
.not( ":submit, :reset, :image, :disabled" )
657658
.not( this.settings.ignore )
658659
.filter( function() {
@@ -786,7 +787,7 @@
786787
normalizer = this.settings.normalizer;
787788
}
788789

789-
// If normalizer is defined, then call it to the changed value instead
790+
// If normalizer is defined, then call it to retreive the changed value instead
790791
// of using the real one.
791792
// Note that `this` in the normalizer is `element`.
792793
if ( normalizer ) {
@@ -1311,17 +1312,6 @@
13111312
return rules;
13121313
},
13131314

1314-
metadataRules: function (element) {
1315-
if (!$.metadata) {
1316-
return {};
1317-
}
1318-
1319-
var meta = $.data(element.form, 'validator').settings.meta;
1320-
return meta ?
1321-
$(element).metadata()[meta] :
1322-
$(element).metadata();
1323-
},
1324-
13251315
dataRules: function( element ) {
13261316
var rules = {},
13271317
$element = $( element ),
@@ -1513,7 +1503,7 @@
15131503

15141504
// https://jqueryvalidation.org/number-method/
15151505
number: function( value, element ) {
1516-
return this.optional( element ) || /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test( value );
1506+
return this.optional( element ) || /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:-?\.\d+)?$/.test( value );
15171507
},
15181508

15191509
// https://jqueryvalidation.org/digits-method/
@@ -1624,11 +1614,12 @@
16241614

16251615
param = typeof param === "string" && { url: param } || param;
16261616
optionDataString = $.param( $.extend( { data: value }, param.data ) );
1627-
if ( previous.old === optionDataString ) {
1617+
if ( previous.valid !== null && previous.old === optionDataString ) {
16281618
return previous.valid;
16291619
}
16301620

16311621
previous.old = optionDataString;
1622+
previous.valid = null;
16321623
validator = this;
16331624
this.startRequest( element );
16341625
data = {};

lib/web/mage/adminhtml/form.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ define([
3434
*/
3535
setHasChanges: function (element) {
3636
var elm;
37+
console.log('test jquery/validate');
3738

3839
if ($(element) && $(element).hasClassName('no-changes')) {
3940
return;

0 commit comments

Comments
 (0)