Skip to content

Commit

Permalink
Merge pull request #42 from open-formulieren/feature/add-min-max-coun…
Browse files Browse the repository at this point in the history
…t-for-selectboxes

Add min max count validator for selectboxes
  • Loading branch information
sergei-maertens authored Feb 5, 2024
2 parents 3187fc9 + 1a64fe0 commit 4ec5a0f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/formio/components/selectboxes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {InputComponentSchema} from '..';
import {OFExtensions} from '../base';
import {ManualValues, Option, VariableValues} from '../common';

type Validator = 'required';
type Validator = 'required' | 'minSelectedCount' | 'maxSelectedCount';
type TranslatableKeys = 'label' | 'description' | 'tooltip';

export type SelectboxesInputSchema = InputComponentSchema<
Expand Down
6 changes: 4 additions & 2 deletions src/formio/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export type BaseErrorKeys =
| 'minDate'
| 'maxDate'
| 'customMessage'
| 'minSelectedCount'
| 'maxSelectedCount'
// custom, added by OF
| 'minTime'
| 'maxTime'
Expand All @@ -44,8 +46,6 @@ type UnsupportedValidateNames =
| 'minLength'
| 'custom'
| 'customPrivate'
| 'minSelectedCount'
| 'maxSelectedCount'
| 'minWords'
| 'maxWords'
| 'email' // email component is exposed, but adds the validation implicitly
Expand All @@ -66,6 +66,8 @@ const VALIDATOR_TO_ERROR_KEY = {
max: 'max',
maxLength: 'maxLength',
pattern: 'pattern',
minSelectedCount: 'minSelectedCount',
maxSelectedCount: 'maxSelectedCount',
// 'email': 'invalid_email', // email component is exposed, but adds the validation implicitly
minDate: 'minDate',
maxDate: 'maxDate',
Expand Down
14 changes: 8 additions & 6 deletions test-d/formio/components/selectboxes.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ expectAssignable<SelectboxesComponentSchema>({
{
value: 'dummy',
label: 'dummy',
}
},
],
});

Expand Down Expand Up @@ -57,11 +57,11 @@ expectAssignable<SelectboxesComponentSchema>({
},
nl: {
label: 'dummy_nl',
}
}
}
}
]
},
},
},
},
],
});

// full, correct schema
Expand Down Expand Up @@ -90,6 +90,8 @@ expectAssignable<SelectboxesComponentSchema>({
validate: {
required: false,
plugins: [],
minSelectedCount: 2,
maxSelectedCount: 3,
},
translatedErrors: {nl: {required: 'Geef checkbox.'}},
errors: {required: 'Geef checkbox.'},
Expand Down

0 comments on commit 4ec5a0f

Please sign in to comment.