Skip to content

Commit

Permalink
feat: Add validation for techniquePicker (#201)
Browse files Browse the repository at this point in the history
Add checks for technique picker
  • Loading branch information
deepaksftc authored Aug 6, 2024
1 parent 1e99bcb commit e2e0306
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/validation/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@user-office-software/duo-validation",
"version": "5.1.6",
"version": "5.1.7",
"description": "Duo frontend and backend validation in one place.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/validation/src/Questionary/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './sampleDeclaration';
export * from './textInput';
export * from './dynamicMultipleChoice';
export * from './instrumentPicker';
export * from './techniquePicker';
30 changes: 30 additions & 0 deletions packages/validation/src/Questionary/techniquePicker.ts
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;
};

0 comments on commit e2e0306

Please sign in to comment.