Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Templates][Identity] Update jquery-validation to 1.20.1 #56744

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Identity/UI/jquery-validate-versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"currentVersion": "1.19.5",
"integrity": "sha256-JwUksNJ6/R07ZiLRoXbGeNrtlFZMFDKX4hemPiHOmCA="
}
"currentVersion": "1.20.1",
"integrity": "sha256-0xVRcEF27BnewkTwGDpseENfeitZEOsQAVSlDc7PgG0="
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<script src="~/Identity/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
</environment>
<environment exclude="Development">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.5/jquery.validate.min.js"
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.20.1/jquery.validate.min.js"
asp-fallback-src="~/Identity/lib/jquery-validation/dist/jquery.validate.min.js"
asp-fallback-test="window.jQuery && window.jQuery.validator"
crossorigin="anonymous"
integrity="sha256-JwUksNJ6/R07ZiLRoXbGeNrtlFZMFDKX4hemPiHOmCA=">
integrity="sha256-0xVRcEF27BnewkTwGDpseENfeitZEOsQAVSlDc7PgG0=">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/4.0.0/jquery.validate.unobtrusive.min.js"
asp-fallback-src="~/Identity/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<script src="~/Identity/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
</environment>
<environment exclude="Development">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.5/jquery.validate.min.js"
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.20.1/jquery.validate.min.js"
asp-fallback-src="~/Identity/lib/jquery-validation/dist/jquery.validate.min.js"
asp-fallback-test="window.jQuery && window.jQuery.validator"
crossorigin="anonymous"
integrity="sha256-JwUksNJ6/R07ZiLRoXbGeNrtlFZMFDKX4hemPiHOmCA=">
integrity="sha256-0xVRcEF27BnewkTwGDpseENfeitZEOsQAVSlDc7PgG0=">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/4.0.0/jquery.validate.unobtrusive.min.js"
asp-fallback-src="~/Identity/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*!
* jQuery Validation Plugin v1.19.5
* jQuery Validation Plugin v1.20.1
*
* https://jqueryvalidation.org/
*
* Copyright (c) 2022 Jörn Zaefferer
* Copyright (c) 2024 Jörn Zaefferer
* Released under the MIT license
*/
(function( factory ) {
Expand Down Expand Up @@ -774,6 +774,9 @@ $.extend( $.validator, {
val = this.elementValue( element ),
result, method, rule, normalizer;

// Abort any pending Ajax request from a previous call to this method.
this.abortRequest( element );

// Prioritize the local normalizer defined for this element over the global one
// if the former exists, otherwise user the global one in case it exists.
if ( typeof rules.normalizer === "function" ) {
Expand Down Expand Up @@ -960,14 +963,23 @@ $.extend( $.validator, {
error.removeClass( this.settings.validClass ).addClass( this.settings.errorClass );

// Replace message on existing label
error.html( message );
if ( this.settings && this.settings.escapeHtml ) {
error.text( message || "" );
} else {
error.html( message || "" );
}
} else {

// Create error element
error = $( "<" + this.settings.errorElement + ">" )
.attr( "id", elementID + "-error" )
.addClass( this.settings.errorClass )
.html( message || "" );
.addClass( this.settings.errorClass );

if ( this.settings && this.settings.escapeHtml ) {
error.text( message || "" );
} else {
error.html( message || "" );
}

// Maintain reference to the element to be placed into the DOM
place = error;
Expand Down Expand Up @@ -1113,6 +1125,10 @@ $.extend( $.validator, {
return !$.validator.methods.required.call( this, val, element ) && "dependency-mismatch";
},

elementAjaxPort: function( element ) {
return "validate" + element.name;
},

startRequest: function( element ) {
if ( !this.pending[ element.name ] ) {
this.pendingRequest++;
Expand Down Expand Up @@ -1148,6 +1164,25 @@ $.extend( $.validator, {
}
},

abortRequest: function( element ) {
var port;

if ( this.pending[ element.name ] ) {
port = this.elementAjaxPort( element );
$.ajaxAbort( port );

this.pendingRequest--;

// Sometimes synchronization fails, make sure pendingRequest is never < 0
if ( this.pendingRequest < 0 ) {
this.pendingRequest = 0;
}

delete this.pending[ element.name ];
$( element ).removeClass( this.settings.pendingClass );
}
},

previousValue: function( element, method ) {
method = typeof method === "string" && method || "remote";

Expand Down Expand Up @@ -1577,18 +1612,19 @@ $.extend( $.validator, {

param = typeof param === "string" && { url: param } || param;
optionDataString = $.param( $.extend( { data: value }, param.data ) );
if ( previous.old === optionDataString ) {
if ( previous.valid !== null && previous.old === optionDataString ) {
return previous.valid;
}

previous.old = optionDataString;
previous.valid = null;
validator = this;
this.startRequest( element );
data = {};
data[ element.name ] = value;
$.ajax( $.extend( true, {
mode: "abort",
port: "validate" + element.name,
port: this.elementAjaxPort( element ),
dataType: "json",
data: data,
context: validator.currentForm,
Expand All @@ -1599,7 +1635,6 @@ $.extend( $.validator, {
validator.settings.messages[ element.name ][ method ] = previous.originalMessage;
if ( valid ) {
submitted = validator.formSubmitted;
validator.resetInternals();
validator.toHide = validator.errorsFor( element );
validator.formSubmitted = submitted;
validator.successList.push( element );
Expand All @@ -1624,6 +1659,7 @@ $.extend( $.validator, {

// Ajax mode: abort
// usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
// $.ajaxAbort( port );
// if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort()

var pendingRequests = {},
Expand All @@ -1634,9 +1670,7 @@ if ( $.ajaxPrefilter ) {
$.ajaxPrefilter( function( settings, _, xhr ) {
var port = settings.port;
if ( settings.mode === "abort" ) {
if ( pendingRequests[ port ] ) {
pendingRequests[ port ].abort();
}
$.ajaxAbort( port );
pendingRequests[ port ] = xhr;
}
} );
Expand All @@ -1648,14 +1682,20 @@ if ( $.ajaxPrefilter ) {
var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode,
port = ( "port" in settings ? settings : $.ajaxSettings ).port;
if ( mode === "abort" ) {
if ( pendingRequests[ port ] ) {
pendingRequests[ port ].abort();
}
$.ajaxAbort( port );
pendingRequests[ port ] = ajax.apply( this, arguments );
return pendingRequests[ port ];
}
return ajax.apply( this, arguments );
};
}

// Abort the previous request without sending a new one
$.ajaxAbort = function( port ) {
if ( pendingRequests[ port ] ) {
pendingRequests[ port ].abort();
delete pendingRequests[ port ];
}
};
return $;
}));

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*!
* jQuery Validation Plugin v1.19.5
* jQuery Validation Plugin v1.20.1
*
* https://jqueryvalidation.org/
*
* Copyright (c) 2022 Jörn Zaefferer
* Copyright (c) 2024 Jörn Zaefferer
* Released under the MIT license
*/
(function( factory ) {
Expand Down Expand Up @@ -774,6 +774,9 @@ $.extend( $.validator, {
val = this.elementValue( element ),
result, method, rule, normalizer;

// Abort any pending Ajax request from a previous call to this method.
this.abortRequest( element );

// Prioritize the local normalizer defined for this element over the global one
// if the former exists, otherwise user the global one in case it exists.
if ( typeof rules.normalizer === "function" ) {
Expand Down Expand Up @@ -960,14 +963,23 @@ $.extend( $.validator, {
error.removeClass( this.settings.validClass ).addClass( this.settings.errorClass );

// Replace message on existing label
error.html( message );
if ( this.settings && this.settings.escapeHtml ) {
error.text( message || "" );
} else {
error.html( message || "" );
}
} else {

// Create error element
error = $( "<" + this.settings.errorElement + ">" )
.attr( "id", elementID + "-error" )
.addClass( this.settings.errorClass )
.html( message || "" );
.addClass( this.settings.errorClass );

if ( this.settings && this.settings.escapeHtml ) {
error.text( message || "" );
} else {
error.html( message || "" );
}

// Maintain reference to the element to be placed into the DOM
place = error;
Expand Down Expand Up @@ -1113,6 +1125,10 @@ $.extend( $.validator, {
return !$.validator.methods.required.call( this, val, element ) && "dependency-mismatch";
},

elementAjaxPort: function( element ) {
return "validate" + element.name;
},

startRequest: function( element ) {
if ( !this.pending[ element.name ] ) {
this.pendingRequest++;
Expand Down Expand Up @@ -1148,6 +1164,25 @@ $.extend( $.validator, {
}
},

abortRequest: function( element ) {
var port;

if ( this.pending[ element.name ] ) {
port = this.elementAjaxPort( element );
$.ajaxAbort( port );

this.pendingRequest--;

// Sometimes synchronization fails, make sure pendingRequest is never < 0
if ( this.pendingRequest < 0 ) {
this.pendingRequest = 0;
}

delete this.pending[ element.name ];
$( element ).removeClass( this.settings.pendingClass );
}
},

previousValue: function( element, method ) {
method = typeof method === "string" && method || "remote";

Expand Down Expand Up @@ -1577,18 +1612,19 @@ $.extend( $.validator, {

param = typeof param === "string" && { url: param } || param;
optionDataString = $.param( $.extend( { data: value }, param.data ) );
if ( previous.old === optionDataString ) {
if ( previous.valid !== null && previous.old === optionDataString ) {
return previous.valid;
}

previous.old = optionDataString;
previous.valid = null;
validator = this;
this.startRequest( element );
data = {};
data[ element.name ] = value;
$.ajax( $.extend( true, {
mode: "abort",
port: "validate" + element.name,
port: this.elementAjaxPort( element ),
dataType: "json",
data: data,
context: validator.currentForm,
Expand All @@ -1599,7 +1635,6 @@ $.extend( $.validator, {
validator.settings.messages[ element.name ][ method ] = previous.originalMessage;
if ( valid ) {
submitted = validator.formSubmitted;
validator.resetInternals();
validator.toHide = validator.errorsFor( element );
validator.formSubmitted = submitted;
validator.successList.push( element );
Expand All @@ -1624,6 +1659,7 @@ $.extend( $.validator, {

// Ajax mode: abort
// usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
// $.ajaxAbort( port );
// if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort()

var pendingRequests = {},
Expand All @@ -1634,9 +1670,7 @@ if ( $.ajaxPrefilter ) {
$.ajaxPrefilter( function( settings, _, xhr ) {
var port = settings.port;
if ( settings.mode === "abort" ) {
if ( pendingRequests[ port ] ) {
pendingRequests[ port ].abort();
}
$.ajaxAbort( port );
pendingRequests[ port ] = xhr;
}
} );
Expand All @@ -1648,14 +1682,20 @@ if ( $.ajaxPrefilter ) {
var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode,
port = ( "port" in settings ? settings : $.ajaxSettings ).port;
if ( mode === "abort" ) {
if ( pendingRequests[ port ] ) {
pendingRequests[ port ].abort();
}
$.ajaxAbort( port );
pendingRequests[ port ] = ajax.apply( this, arguments );
return pendingRequests[ port ];
}
return ajax.apply( this, arguments );
};
}

// Abort the previous request without sending a new one
$.ajaxAbort = function( port ) {
if ( pendingRequests[ port ] ) {
pendingRequests[ port ].abort();
delete pendingRequests[ port ];
}
};
return $;
}));

Large diffs are not rendered by default.

Loading
Loading