@@ -260,35 +260,49 @@ class Pattern extends BasePattern {
260
260
this . check_input ( { input : not_before_el , stop : true } ) ;
261
261
}
262
262
} else if ( input_options . minValues || input_options . maxValues ) {
263
-
264
263
const min_values = input_options . minValues !== null && parseInt ( input_options . minValues , 10 )
265
264
const max_values = input_options . maxValues !== null && parseInt ( input_options . maxValues , 10 )
266
265
267
- // This makes only sense for inputs with the same name.
268
- const valued_siblings = [ ... this . el . elements ] . filter ( ( el ) => {
266
+ let number_values = 0 ;
267
+ for ( const _inp of this . el . elements ) {
269
268
// Filter for siblings with same name.
270
- if ( el . name !== input . name ) {
271
- return false ;
269
+ if (
270
+ // Keep only inputs with same name
271
+ _inp . name !== input . name
272
+ // Skip all form elements which are no input elements
273
+ || ! [ "INPUT" , "SELECT" , "TEXTAREA" ] . includes ( _inp . tagName )
274
+ ) {
275
+ continue ;
272
276
}
273
277
274
- // Check if checkboxes or radios are selected ...
275
- if ( el . type === "checkbox" || el . type === "radio" ) {
276
- return el . checked ;
278
+ // Check if checkboxes or radios are checked ...
279
+ if ( _inp . type === "checkbox" || _inp . type === "radio" ) {
280
+ if ( _inp . checked ) {
281
+ number_values ++ ;
282
+ }
283
+ continue ;
277
284
}
278
285
279
- // ... or inputs have a value set.
280
- // TODO: are multiple non-check/radio inputs with same name even possible?
281
- return el . value !== undefined ;
282
- } ) ;
286
+ // Select, if select is selected.
287
+ if ( _inp . tagName === "SELECT" ) {
288
+ number_values += _inp . selectedOptions . length ;
289
+ continue ;
290
+ }
291
+
292
+ // For the rest a value must be set.
293
+ if ( _inp . value === 0 || _inp . value ) {
294
+ number_values ++ ;
295
+ }
296
+ }
283
297
284
- if ( max_values !== null && valued_siblings . length > max_values ) {
298
+ if ( max_values !== null && number_values > max_values ) {
285
299
this . set_error ( {
286
300
input : input ,
287
301
msg : input_options . message [ "max-values" ] ,
288
302
max : max_values ,
289
303
} )
290
304
}
291
- if ( min_values !== null && valued_siblings . length < min_values ) {
305
+ if ( min_values !== null && number_values < min_values ) {
292
306
this . set_error ( {
293
307
input : input ,
294
308
msg : input_options . message [ "min-values" ] ,
0 commit comments