diff --git a/src/pages/admin/DynamicForm/FormCreate.js b/src/pages/admin/DynamicForm/FormCreate.js index 157c6547..a059cad9 100644 --- a/src/pages/admin/DynamicForm/FormCreate.js +++ b/src/pages/admin/DynamicForm/FormCreate.js @@ -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) diff --git a/src/pages/public/RegistrationForms/MembershipForm/index.js b/src/pages/public/RegistrationForms/MembershipForm/index.js index 67f6aa48..d38c0eeb 100644 --- a/src/pages/public/RegistrationForms/MembershipForm/index.js +++ b/src/pages/public/RegistrationForms/MembershipForm/index.js @@ -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; }) }); @@ -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; }) }); @@ -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; }) }); @@ -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; }) }); diff --git a/src/pages/public/RegistrationForms/UserMembershipForm/index.js b/src/pages/public/RegistrationForms/UserMembershipForm/index.js index f5b7863f..d6f00a2d 100644 --- a/src/pages/public/RegistrationForms/UserMembershipForm/index.js +++ b/src/pages/public/RegistrationForms/UserMembershipForm/index.js @@ -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; }), }); @@ -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; }), }); @@ -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; }), }); @@ -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; }), });