@@ -132,6 +132,11 @@ class Pattern extends BasePattern {
132
132
) ;
133
133
}
134
134
135
+ siblings ( input ) {
136
+ // Get all siblings of an input with the same name.
137
+ return this . inputs . filter ( ( _input ) => _input . name === input . name ) ;
138
+ }
139
+
135
140
validate_all ( event ) {
136
141
// Check all inputs.
137
142
for ( const input of this . inputs ) {
@@ -297,17 +302,7 @@ class Pattern extends BasePattern {
297
302
const max_values = input_options . maxValues !== null && parseInt ( input_options . maxValues , 10 ) || null ;
298
303
299
304
let number_values = 0 ;
300
- for ( const _inp of this . form . elements ) {
301
- // Filter for siblings with same name.
302
- if (
303
- // Keep only inputs with same name
304
- _inp . name !== input . name
305
- // Skip all form elements which are no input elements
306
- || ! [ "INPUT" , "SELECT" , "TEXTAREA" ] . includes ( _inp . tagName )
307
- ) {
308
- continue ;
309
- }
310
-
305
+ for ( const _inp of this . siblings ( input ) ) {
311
306
// Check if checkboxes or radios are checked ...
312
307
if ( _inp . type === "checkbox" || _inp . type === "radio" ) {
313
308
if ( _inp . checked ) {
@@ -433,8 +428,7 @@ class Pattern extends BasePattern {
433
428
msg = msg . replace ( / % { value} / g, JSON . stringify ( input . value ) ) ;
434
429
435
430
// Set the error state the input itself and on all siblings, if any.
436
- const inputs = [ ...this . form . elements ] . filter ( ( _input ) => _input . name === input . name ) ;
437
- for ( const _input of inputs ) {
431
+ for ( const _input of this . siblings ( input ) ) {
438
432
_input . setCustomValidity ( msg ) ;
439
433
}
440
434
// Store the error message on the input.
@@ -458,7 +452,7 @@ class Pattern extends BasePattern {
458
452
let inputs = [ input ] ;
459
453
if ( all_of_group ) {
460
454
// Get all inputs with the same name - e.g. radio buttons, checkboxes.
461
- inputs = [ ... this . form . elements ] . filter ( ( _input ) => _input . name === input . name ) ;
455
+ inputs = this . siblings ( input ) ;
462
456
}
463
457
for ( const it of inputs ) {
464
458
if ( clear_state ) {
@@ -495,7 +489,7 @@ class Pattern extends BasePattern {
495
489
496
490
// Do not set a error message for a input group like radio buttons or
497
491
// checkboxes where one has already been set.
498
- const inputs = [ ... this . form . elements ] . filter ( ( _input ) => _input . name === input . name ) ;
492
+ const inputs = this . siblings ( input ) ;
499
493
if ( inputs . length > 1 && inputs . some ( ( it ) => ! ! it [ KEY_ERROR_EL ] ) ) {
500
494
// error message for input group already set.
501
495
return ;
0 commit comments