Closed Bhasker1998 closed 1 month ago
Think you need to do:
yup.string().when("role", {
is: "teacher",
then: (shcema) => schema.required("School is required"),
otherwise: (schema) => schema.notRequired(),
})
Thank you for the clarification .
On Wed, 24 Jul 2024 at 17:27, marc-at-brightnight @.***> wrote:
Think you need to do:
yup.string().when("role", { is: "teacher", then: (shcema) => schema.required("School is required"), otherwise: (schema) => schema.notRequired(), })
— Reply to this email directly, view it on GitHub https://github.com/jquense/yup/issues/2231#issuecomment-2247726155, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHZ4YL4YZZMK5AUAYQPB2TLZN6JBXAVCNFSM6AAAAABK2RQXCGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBXG4ZDMMJVGU . You are receiving this because you authored the thread.Message ID: @.***>
what if we want to give the object schema in this how can we do subjects: yup .object() .shape() .when('class', { is: (val) => val === 9 || val === 10, then: (schema) => yup.object().shape({ mil: yup.string().required('Mil is required'), sil: yup.string().required('Sil is required'), comp_sub_1: yup.string().required('comp sub 1 is required'), comp_sub_2: yup.string().required('comp sub 2 is required'), comp_sub_3: yup.string().required('comp sub 3 is required'), comp_sub_4: yup.string().required('comp sub 4 is required') }), otherwise: (schema) => yup.object().shape({ comp_sub_1: yup.string().required('comp sub 1 is required'), comp_sub_2: yup.string().required('comp sub 2 is required'), elective_1: yup.string().required('elective_1 is required'), elective_2: yup.string().required('elective 2 is required'), elective_3: yup.string().required('elective 3 is required'), additional: yup.string().required('additional is required') }) }) this is not working
On Wed, 24 Jul 2024 at 17:27, marc-at-brightnight @.***> wrote:
Think you need to do:
yup.string().when("role", { is: "teacher", then: (shcema) => schema.required("School is required"), otherwise: (schema) => schema.notRequired(), })
— Reply to this email directly, view it on GitHub https://github.com/jquense/yup/issues/2231#issuecomment-2247726155, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHZ4YL4YZZMK5AUAYQPB2TLZN6JBXAVCNFSM6AAAAABK2RQXCGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBXG4ZDMMJVGU . You are receiving this because you authored the thread.Message ID: @.***>
its resolved thankyou
On Mon, 29 Jul 2024 at 23:17, bhaskar prajapati @.***> wrote:
what if we want to give the object schema in this how can we do subjects: yup .object() .shape() .when('class', { is: (val) => val === 9 || val === 10, then: (schema) => yup.object().shape({ mil: yup.string().required('Mil is required'), sil: yup.string().required('Sil is required'), comp_sub_1: yup.string().required('comp sub 1 is required'), comp_sub_2: yup.string().required('comp sub 2 is required'), comp_sub_3: yup.string().required('comp sub 3 is required'), comp_sub_4: yup.string().required('comp sub 4 is required') }), otherwise: (schema) => yup.object().shape({ comp_sub_1: yup.string().required('comp sub 1 is required'), comp_sub_2: yup.string().required('comp sub 2 is required'), elective_1: yup.string().required('elective_1 is required'), elective_2: yup.string().required('elective 2 is required'), elective_3: yup.string().required('elective 3 is required'), additional: yup.string().required('additional is required') }) }) this is not working
On Wed, 24 Jul 2024 at 17:27, marc-at-brightnight < @.***> wrote:
Think you need to do:
yup.string().when("role", { is: "teacher", then: (shcema) => schema.required("School is required"), otherwise: (schema) => schema.notRequired(), })
— Reply to this email directly, view it on GitHub https://github.com/jquense/yup/issues/2231#issuecomment-2247726155, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHZ4YL4YZZMK5AUAYQPB2TLZN6JBXAVCNFSM6AAAAABK2RQXCGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBXG4ZDMMJVGU . You are receiving this because you authored the thread.Message ID: @.***>
I m using the yup latest version 1.4 and i m using the yup.string().when("role", { is: "teacher", then: yup.string().required("School is required"), otherwise: yup.string().notRequired(), })
this thing is giving me error Validation failed: TypeError: branch is not a function line no 183 in node_modules index.js file
on version 0.32.11 is working fine