-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add validation for techniquePicker (#201)
Add checks for technique picker
- Loading branch information
1 parent
1e99bcb
commit e2e0306
Showing
4 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as Yup from 'yup'; | ||
import { AnyObject } from 'yup/lib/types'; | ||
|
||
export const techniquePickerValidationSchema = (field: any) => { | ||
const config = field.config; | ||
|
||
let schema: | ||
| Yup.ArraySchema< | ||
Yup.NumberSchema<number | null | undefined>, | ||
AnyObject, | ||
(number | undefined)[] | null | undefined | ||
> | ||
| Yup.NumberSchema<number | null | undefined>; | ||
|
||
if (config.isMultipleSelect) { | ||
schema = Yup.array().of(Yup.number()).nullable(); | ||
|
||
if (config.required) { | ||
schema = schema.min(1, 'Please select a technique'); | ||
} | ||
} else { | ||
schema = Yup.number().positive().integer().nullable(); | ||
|
||
if (config.required) { | ||
schema = schema.required('This is a required field'); | ||
} | ||
} | ||
|
||
return schema; | ||
}; |