Skip to content

Commit

Permalink
Item15330: update form validation to latest upstream version
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed May 21, 2024
1 parent 9537dd2 commit c60dde8
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 152 deletions.
4 changes: 2 additions & 2 deletions JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/VALIDATE.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sub new {
my $this = bless(
$class->SUPER::new(
name => 'Validate',
version => '1.19.6_1',
version => '1.20.0',
author => 'Joern Zaefferer',
homepage => 'http://jqueryvalidation.org/',
javascript => ['pkg.js'],
Expand Down Expand Up @@ -76,7 +76,7 @@ sub init {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2010-2022 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2010-2024 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*!
* jQuery Validation Plugin v1.19.6-pre
* jQuery Validation Plugin v1.20.0
*
* https://jqueryvalidation.org/
*
* Copyright (c) 2022 Jörn Zaefferer
* Copyright (c) 2023 Jörn Zaefferer
* Released under the MIT license
*/
(function( factory ) {
Expand Down Expand Up @@ -1459,46 +1459,39 @@ $.validator.addMethod( "url2", function( value, element ) {
* @cat Plugins/Validate/Methods
*/
$.validator.addMethod( "vinUS", function( v ) {
if ( v.length !== 17 ) {
return false;
}

var LL = [ "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" ],
VL = [ 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 7, 9, 2, 3, 4, 5, 6, 7, 8, 9 ],
FL = [ 8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2 ],
rs = 0,
i, n, d, f, cd, cdv;
if ( v.length !== 17 ) {
return false;
}

for ( i = 0; i < 17; i++ ) {
f = FL[ i ];
d = v.slice( i, i + 1 );
if ( i === 8 ) {
cdv = d;
}
if ( !isNaN( d ) ) {
d *= f;
} else {
for ( n = 0; n < LL.length; n++ ) {
if ( d.toUpperCase() === LL[ n ] ) {
d = VL[ n ];
d *= f;
if ( isNaN( cdv ) && n === 8 ) {
cdv = LL[ n ];
}
break;
}
}
}
rs += d;
}
cd = rs % 11;
if ( cd === 10 ) {
cd = "X";
}
if ( cd === cdv ) {
return true;
}
return false;
var LL = [ "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" ],
VL = [ 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 7, 9, 2, 3, 4, 5, 6, 7, 8, 9 ],
FL = [ 8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2 ],
rs = 0,
i, n, d, f, cd, cdv;

for ( i = 0; i < 17; i++ ) {
f = FL[ i ];
d = v.slice( i, i + 1 );
if ( isNaN( d ) ) {
d = d.toUpperCase();
n = VL[ LL.indexOf( d ) ];
} else {
n = parseInt( d, 10 );
}
if ( i === 8 )
{
cdv = n;
if ( d === "X" ) {
cdv = 10;
}
}
rs += n * f;
}
cd = rs % 11;
if ( cd === cdv ) {
return true;
}
return false;
}, "The specified vehicle identification number (VIN) is invalid." );

$.validator.addMethod( "zipcodeUS", function( value, element ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*!
* jQuery Validation Plugin v1.19.6-pre
* jQuery Validation Plugin v1.20.0
*
* https://jqueryvalidation.org/
*
* Copyright (c) 2022 Jörn Zaefferer
* Copyright (c) 2023 Jörn Zaefferer
* Released under the MIT license
*/
(function( factory ) {
Expand Down Expand Up @@ -1459,46 +1459,39 @@ $.validator.addMethod( "url2", function( value, element ) {
* @cat Plugins/Validate/Methods
*/
$.validator.addMethod( "vinUS", function( v ) {
if ( v.length !== 17 ) {
return false;
}

var LL = [ "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" ],
VL = [ 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 7, 9, 2, 3, 4, 5, 6, 7, 8, 9 ],
FL = [ 8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2 ],
rs = 0,
i, n, d, f, cd, cdv;
if ( v.length !== 17 ) {
return false;
}

for ( i = 0; i < 17; i++ ) {
f = FL[ i ];
d = v.slice( i, i + 1 );
if ( i === 8 ) {
cdv = d;
}
if ( !isNaN( d ) ) {
d *= f;
} else {
for ( n = 0; n < LL.length; n++ ) {
if ( d.toUpperCase() === LL[ n ] ) {
d = VL[ n ];
d *= f;
if ( isNaN( cdv ) && n === 8 ) {
cdv = LL[ n ];
}
break;
}
}
}
rs += d;
}
cd = rs % 11;
if ( cd === 10 ) {
cd = "X";
}
if ( cd === cdv ) {
return true;
}
return false;
var LL = [ "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" ],
VL = [ 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 7, 9, 2, 3, 4, 5, 6, 7, 8, 9 ],
FL = [ 8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2 ],
rs = 0,
i, n, d, f, cd, cdv;

for ( i = 0; i < 17; i++ ) {
f = FL[ i ];
d = v.slice( i, i + 1 );
if ( isNaN( d ) ) {
d = d.toUpperCase();
n = VL[ LL.indexOf( d ) ];
} else {
n = parseInt( d, 10 );
}
if ( i === 8 )
{
cdv = n;
if ( d === "X" ) {
cdv = 10;
}
}
rs += n * f;
}
cd = rs % 11;
if ( cd === cdv ) {
return true;
}
return false;
}, "The specified vehicle identification number (VIN) is invalid." );

$.validator.addMethod( "zipcodeUS", function( value, element ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*!
* jQuery Validation Plugin v1.19.6-pre
* jQuery Validation Plugin v1.20.0
*
* https://jqueryvalidation.org/
*
* Copyright (c) 2022 Jörn Zaefferer
* Copyright (c) 2023 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 @@ -1588,7 +1623,7 @@ $.extend( $.validator, {
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 +1634,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 +1658,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 +1669,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 +1681,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 $;
}));
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ $.extend( $.validator.messages, {
email2: "Veuillez fournir une adresse électronique valide.",
url2: "Veuillez fournir une adresse URL valide.",
creditcardtypes: "Veuillez fournir un numéro de carte de crédit valide.",
currency: "Veuillez fournir une monnaie valide.",
ipv4: "Veuillez fournir une adresse IP v4 valide.",
ipv6: "Veuillez fournir une adresse IP v6 valide.",
require_from_group: $.validator.format( "Veuillez fournir au moins {0} de ces champs." ),
Expand Down
Loading

0 comments on commit c60dde8

Please sign in to comment.