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

fix: validation error when element not found #1620

Merged
merged 3 commits into from
Dec 13, 2024
Merged
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
3 changes: 2 additions & 1 deletion js/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@

// Clear fields' values.
var $inputs = $clone.find( rwmb.inputSelectors );
const count = $container.children( '.rwmb-clone' ).length;
let count = $container.children( '.rwmb-clone' ).length;

// The first clone should keep the default values.
if ( count > 1 ) {
Expand All @@ -162,6 +162,7 @@

// Insert clone.
$clone.insertAfter( $last );
count++;

// Trigger custom event for the clone instance. Required for Group extension to update sub fields.
$clone.trigger( 'clone_instance', nextIndex );
Expand Down
29 changes: 16 additions & 13 deletions js/validation/jquery.validate.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*!
* jQuery Validation Plugin v1.20.0
* jQuery Validation Plugin v1.21.0
*
* https://jqueryvalidation.org/
*
* Copyright (c) 2023 Jörn Zaefferer
* Copyright (c) 2024 JÃķrn Zaefferer
* Released under the MIT license
*/
(function( factory ) {
Expand Down Expand Up @@ -293,6 +293,7 @@ $.extend( $.validator, {
onsubmit: true,
ignore: ":hidden",
ignoreTitle: false,
customElements: [],
onfocusin: function( element ) {
this.lastActive = element;

Expand Down Expand Up @@ -440,17 +441,17 @@ $.extend( $.validator, {
settings[ eventType ].call( validator, this, event );
}
}

var focusListeners = [ ":text", "[type='password']", "[type='file']", "select", "textarea", "[type='number']", "[type='search']",
"[type='tel']", "[type='url']", "[type='email']", "[type='datetime']", "[type='date']", "[type='month']",
"[type='week']", "[type='time']", "[type='datetime-local']", "[type='range']", "[type='color']",
"[type='radio']", "[type='checkbox']", "[contenteditable]", "[type='button']" ];
var clickListeners = [ "select", "option", "[type='radio']", "[type='checkbox']" ];
$( this.currentForm )
.on( "focusin.validate focusout.validate keyup.validate",
":text, [type='password'], [type='file'], select, textarea, [type='number'], [type='search'], " +
"[type='tel'], [type='url'], [type='email'], [type='datetime'], [type='date'], [type='month'], " +
"[type='week'], [type='time'], [type='datetime-local'], [type='range'], [type='color'], " +
"[type='radio'], [type='checkbox'], [contenteditable], [type='button']", delegate )
.on( "focusin.validate focusout.validate keyup.validate", focusListeners.concat( this.settings.customElements ).join( ", " ), delegate )

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

if ( this.settings.invalidHandler ) {
$( this.currentForm ).on( "invalid-form.validate", this.settings.invalidHandler );
Expand Down Expand Up @@ -647,11 +648,12 @@ $.extend( $.validator, {

elements: function() {
var validator = this,
rulesCache = {};
rulesCache = {},
selectors = [ "input", "select", "textarea", "[contenteditable]" ];

// Select all valid inputs inside the form (no submit or reset buttons)
return $( this.currentForm )
.find( "input, select, textarea, [contenteditable]" )
.find( selectors.concat( this.settings.customElements ).join( ", " ) )
.not( ":submit, :reset, :image, :disabled" )
.not( this.settings.ignore )
.filter( function() {
Expand Down Expand Up @@ -1501,7 +1503,7 @@ $.extend( $.validator, {

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

// https://jqueryvalidation.org/digits-method/
Expand Down Expand Up @@ -1612,11 +1614,12 @@ $.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 = {};
Expand Down
5 changes: 5 additions & 0 deletions js/validation/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@
for ( var i = 0, elements = ( this.currentElements = this.elements() ); elements[ i ]; i++ ) {
if ( this.findByName( elements[ i ].name ).length !== undefined && this.findByName( elements[ i ].name ).length > 1 ) {
for ( var cnt = 0; cnt < this.findByName( elements[ i ].name ).length; cnt++ ) {
const isTargetExists = this.validationTargetFor( this.clean( this.findByName( elements[ i ].name )[ cnt ] ) );
if ( typeof isTargetExists === 'undefined' ) {
continue;
}

this.check( this.findByName( elements[ i ].name )[ cnt ] );
}
} else {
Expand Down
Loading