Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update file upload validation schema #191

Merged
merged 5 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.0.0",
"version": "5.0.1",
"description": "Duo frontend and backend validation in one place.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
24 changes: 9 additions & 15 deletions packages/validation/src/Questionary/fileUpload.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import * as Yup from 'yup';

export const fileUploadQuestionValidationSchema = (field: any) => {
const config = field.config;

let schema = Yup.array().of(
Yup.object({ id: Yup.string().required() }).required()
);

config.required &&
(schema = schema.required('This is a required field').min(1));

config.max_files &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ellen-wright I am not sure why do we want to remove the max_files from the check here. Is it removed from the config or?

(schema = schema.max(config.max_files, `Max ${config.max} files`));

return schema;
};
export const fileUploadQuestionValidationSchema = (answer: any) => {
const config = answer.config;
let schema = Yup.array();
if (config.required) {
schema = schema.min(1, `Please upload a file.`);
}

return schema;
};