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

Bugfix yup when #446

Merged
merged 3 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 6 additions & 3 deletions src/pages/admin/DynamicForm/FormCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -851,9 +851,12 @@ const FormCreate = (props) => {
.required(),
price: Yup.number("Valid number required")
.min(0, "Valid pricing required"),
nonMembersPrice: Yup.number("Valid number required").when("nonMembersAllowed", {
is: true,
then: Yup.number().min(Yup.ref("price"), "Non-members price must be greater or equal to members price")
nonMembersAllowed: Yup.bool(),
nonMembersPrice: Yup.number("Valid number required").when("nonMembersAllowed", (nonMembersAllowed, schema) => {
if (nonMembersAllowed) {
return schema.min(Yup.ref("price"), "Non-members price must be greater or equal to members price");
}
return schema;
}),
registrationQuestions: Yup.array().of(regQuestionSchema),
partnerRegistrationQuestions: Yup.array().of(regQuestionSchema)
Expand Down
36 changes: 20 additions & 16 deletions src/pages/public/RegistrationForms/MembershipForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ const MembershipFormContainer = (props) => {
last_name: Yup.string().required("Last name is required"),
education: Yup.string().required("Education is required"),
prev_member: Yup.string().required("Please select Yes/No"),
heardFromSpecify: Yup.string().when("heard_from", {
is: (val) =>
val && (val === "Events" || val === "Boothing" || val === "Other"),
then: Yup.string().required("Please fill in this field")
heardFromSpecify: Yup.string().when("heard_from", (heard_from, schema) => {
if (heard_from && ["Events", "Boothing", "Other"].some(val => heard_from?.includes(val))) {
return schema.required("Please fill in this field");
}
return schema;
})
});

Expand All @@ -111,10 +112,11 @@ const MembershipFormContainer = (props) => {
"International or domestic student indication is required"
),
prev_member: Yup.string().required("Please select Yes/No"),
heardFromSpecify: Yup.string().when("heard_from", {
is: (val) =>
val && (val === "Events" || val === "Boothing" || val === "Other"),
then: Yup.string().required("Please fill in this field")
heardFromSpecify: Yup.string().when("heard_from", (heard_from, schema) => {
if (heard_from && ["Events", "Boothing", "Other"].some(val => heard_from?.includes(val))) {
return schema.required("Please fill in this field");
}
return schema;
})
});

Expand All @@ -127,10 +129,11 @@ const MembershipFormContainer = (props) => {
year: Yup.string().required("Level of study is required"),
major: Yup.string().required("Major is required"),
prev_member: Yup.string().required("Please select Yes/No"),
heardFromSpecify: Yup.string().when("heard_from", {
is: (val) =>
val && (val === "Events" || val === "Boothing" || val === "Other"),
then: Yup.string().required("Please fill in this field")
heardFromSpecify: Yup.string().when("heard_from", (heard_from, schema) => {
if (heard_from && ["Events", "Boothing", "Other"].some(val => heard_from?.includes(val))) {
return schema.required("Please fill in this field");
}
return schema;
})
});

Expand All @@ -141,10 +144,11 @@ const MembershipFormContainer = (props) => {
year: Yup.string().required("Level of study is required"),
high_school: Yup.string().required("High School is required"),
prev_member: Yup.string().required("Please select Yes/No"),
heardFromSpecify: Yup.string().when("heard_from", {
is: (val) =>
val && (val === "Events" || val === "Boothing" || val === "Other"),
then: Yup.string().required("Please fill in this field")
heardFromSpecify: Yup.string().when("heard_from", (heard_from, schema) => {
if (heard_from && ["Events", "Boothing", "Other"].some(val => heard_from?.includes(val))) {
return schema.required("Please fill in this field");
}
return schema;
})
});

Expand Down
32 changes: 20 additions & 12 deletions src/pages/public/RegistrationForms/UserMembershipForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ const UserMembershipFormContainer = (props) => {
last_name: Yup.string().required("Last name is required"),
education: Yup.string().required("Education is required"),
prev_member: Yup.string().required("Please select Yes/No"),
heardFromSpecify: Yup.string().when("heard_from", {
is: val => (val && (val === "Events" || val === "Boothing" || val === "Other")),
then: Yup.string().required("Please fill in this field")
heardFromSpecify: Yup.string().when("heard_from", (heard_from, schema) => {
if (heard_from && ["Events", "Boothing", "Other"].some(val => heard_from?.includes(val))) {
return schema.required("Please fill in this field");
}
return schema;
}),
});

Expand All @@ -110,9 +112,11 @@ const UserMembershipFormContainer = (props) => {
prev_member: Yup.string().required("Please select Yes/No"),
pronouns: Yup.string(),
diet: Yup.string(),
heardFromSpecify: Yup.string().when("heard_from", {
is: val => (val && (val === "Events" || val === "Boothing" || val === "Other")),
then: Yup.string().required("Please fill in this field")
heardFromSpecify: Yup.string().when("heard_from", (heard_from, schema) => {
if (heard_from && ["Events", "Boothing", "Other"].some(val => heard_from?.includes(val))) {
return schema.required("Please fill in this field");
}
return schema;
}),
});

Expand All @@ -130,9 +134,11 @@ const UserMembershipFormContainer = (props) => {
year: Yup.string().required("Level of study is required"),
major: Yup.string().required("Major is required"),
prev_member: Yup.string().required("Please select Yes/No"),
heardFromSpecify: Yup.string().when("heard_from", {
is: val => (val && (val === "Events" || val === "Boothing" || val === "Other")),
then: Yup.string().required("Please fill in this field")
heardFromSpecify: Yup.string().when("heard_from", (heard_from, schema) => {
if (heard_from && ["Events", "Boothing", "Other"].some(val => heard_from?.includes(val))) {
return schema.required("Please fill in this field");
}
return schema;
}),
});

Expand All @@ -148,9 +154,11 @@ const UserMembershipFormContainer = (props) => {
year: Yup.string().required("Level of study is required"),
high_school: Yup.string().required("High School is required"),
prev_member: Yup.string().required("Please select Yes/No"),
heardFromSpecify: Yup.string().when("heard_from", {
is: val => (val && (val === "Events" || val === "Boothing" || val === "Other")),
then: Yup.string().required("Please fill in this field")
heardFromSpecify: Yup.string().when("heard_from", (heard_from, schema) => {
if (heard_from && ["Events", "Boothing", "Other"].some(val => heard_from?.includes(val))) {
return schema.required("Please fill in this field");
}
return schema;
}),
});

Expand Down