@@ -69,6 +69,20 @@ class Pattern extends BasePattern {
69
69
this . form . setAttribute ( "novalidate" , "" ) ;
70
70
}
71
71
72
+ get inputs ( ) {
73
+ // Return all inputs elements
74
+ return [ ...this . form . elements ] . filter ( ( input ) =>
75
+ input . matches ( "input[name], select[name], textarea[name]" )
76
+ ) ;
77
+ }
78
+
79
+ get disableable ( ) {
80
+ // Return all elements, which should be disabled when there are errors.
81
+ return [ ...this . form . elements ] . filter ( ( input ) =>
82
+ input . matches ( this . options . disableSelector )
83
+ ) ;
84
+ }
85
+
72
86
validate_all ( event ) {
73
87
// Check all inputs.
74
88
for ( const input of this . inputs ) {
@@ -77,13 +91,6 @@ class Pattern extends BasePattern {
77
91
}
78
92
79
93
initialize_inputs ( ) {
80
- this . inputs = [
81
- ...this . form . querySelectorAll ( "input[name], select[name], textarea[name]" ) ,
82
- ] ;
83
- this . disabled_elements = [
84
- ...this . form . querySelectorAll ( this . options . disableSelector ) ,
85
- ] ;
86
-
87
94
for ( const [ cnt , input ] of this . inputs . entries ( ) ) {
88
95
// Cancelable debouncer.
89
96
const debouncer = utils . debounce ( ( e ) => {
@@ -365,7 +372,7 @@ class Pattern extends BasePattern {
365
372
let inputs = [ input ] ;
366
373
if ( all_of_group ) {
367
374
// Get all inputs with the same name - e.g. radio buttons, checkboxes.
368
- inputs = this . inputs . filter ( ( it ) => it . name === input . name ) ;
375
+ inputs = [ ... this . form . elements ] . filter ( ( _input ) => _input . name === input . name ) ;
369
376
}
370
377
for ( const it of inputs ) {
371
378
if ( clear_state ) {
@@ -378,7 +385,7 @@ class Pattern extends BasePattern {
378
385
379
386
// disable selector
380
387
if ( this . form . checkValidity ( ) ) {
381
- for ( const it of this . disabled_elements ) {
388
+ for ( const it of this . disableable ) {
382
389
if ( it . disabled ) {
383
390
it . removeAttribute ( "disabled" ) ;
384
391
it . classList . remove ( "disabled" ) ;
@@ -402,7 +409,7 @@ class Pattern extends BasePattern {
402
409
403
410
// Do not set a error message for a input group like radio buttons or
404
411
// checkboxes where one has already been set.
405
- const inputs = this . inputs . filter ( ( it ) => it . name === input . name ) ;
412
+ const inputs = [ ... this . form . elements ] . filter ( ( _input ) => _input . name === input . name ) ;
406
413
if ( inputs . length > 1 && inputs . some ( ( it ) => ! ! it [ KEY_ERROR_EL ] ) ) {
407
414
// error message for input group already set.
408
415
return ;
@@ -426,7 +433,7 @@ class Pattern extends BasePattern {
426
433
input [ KEY_ERROR_EL ] = error_node ;
427
434
428
435
let did_disable = false ;
429
- for ( const it of this . disabled_elements ) {
436
+ for ( const it of this . disableable ) {
430
437
// Disable for melements if they are not already disabled and which
431
438
// do not have set the `formnovalidate` attribute, e.g.
432
439
// `<button formnovalidate>cancel</button>`.
0 commit comments