Skip to content

Commit

Permalink
fix: asterisk in cloneable field
Browse files Browse the repository at this point in the history
  • Loading branch information
tanftw committed Jan 10, 2025
1 parent 523b65d commit 6a2face
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions js/validation/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,12 @@
* group[1][subgroup][1][field][1][] => field // Cloneable group with cloneable subgroup with cloneable fields with multiple values: file, checkbox list, etc.
*/
const getValidationKey = name => {
// For fields without [], early return the name.
if ( name.at( '-1' ) !== ']' ) {
return name;
}

// Detect name parts in format of anything[] or anything[1].
let parts = name.match( /^(.+?)(?:\[\d+\]|(?:\[\]))?$/ );

if ( parts[ 1 ] && isNaN( parts[ 1 ] ) ) {
// Remove []
let words = name.match( /(\w+)|(\[\w+\])/g );
let words = name.match( /([\w-]+)|(\[\w+\])/g );
let resultArray = [ words.join( "" ) ];

// Remove characters "[" and "]".
Expand Down Expand Up @@ -184,6 +179,10 @@
if ( !$el.length ) {
$el = $( '[name*="[' + k + ']"]' ); // Subfields in groups.
}
if ( !$el.length ) {
$el = $( '[name*="' + k + '"]' ); // contains field ID.
}

if ( $el.length ) {
$el.closest( '.rwmb-input' ).siblings( '.rwmb-label' ).find( 'label' ).append( '<span class="rwmb-required">*</span>' );
}
Expand Down

0 comments on commit 6a2face

Please sign in to comment.