@@ -25,6 +25,8 @@ parser.addArgument("message-equality", "is not equal to %{attribute}.");
25
25
parser . addArgument ( "not-after" , null ) ;
26
26
parser . addArgument ( "not-before" , null ) ;
27
27
parser . addArgument ( "equality" , null ) ;
28
+ parser . addArgument ( "min-selection" , null ) ;
29
+ parser . addArgument ( "max-selection" , null ) ;
28
30
parser . addArgument ( "delay" , 100 ) ; // Delay before validation is done to avoid validating while typing.
29
31
30
32
// BBB
@@ -255,6 +257,35 @@ class Pattern extends BasePattern {
255
257
logger . debug ( "Check `no-before` input." , not_after_el ) ;
256
258
this . check_input ( { input : not_before_el , stop : true } ) ;
257
259
}
260
+ } else if ( input_options . minSelection || input_options . maxSelection )
261
+ // This makes only sense for inputs with the same name.
262
+ const valued_siblings = [ ...this . el . elements ] . filter ( ( el ) => {
263
+ // Filter for siblings with same name.
264
+ if ( el . name !== input . name ) {
265
+ return false ;
266
+ }
267
+
268
+ // Check if they are selected or have an value
269
+ if ( el . type === "checkbox" || el . type === "radio" ) {
270
+ return el . checked ;
271
+ }
272
+
273
+ // ... or have a value set.
274
+ return el . value !== undefined ;
275
+ } ) ;
276
+
277
+ if ( valued_siblings > input_options . maxSelection ) {
278
+ this . set_error ( {
279
+ input : input ,
280
+ msg : "You have exceeded the maximum number of selections."
281
+ } )
282
+ }
283
+ if ( valued_siblings < input_options . minSelection ) {
284
+ this . set_error ( {
285
+ input : input ,
286
+ msg : "You need to select at least..."
287
+ } )
288
+ }
258
289
}
259
290
260
291
if ( ! validity_state . customError ) {
0 commit comments