-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Validation Error #3923
Comments
Hey @Master-Daniel . My team run into same issue. Solution was quite simple. W use Formik with YUP for validation schema. We have upgraded both, and then error occurs. I had to downgrade YUP library to previous version, due to incompatibility between versions pre v1.0 and versions 1... At the moment of writing it looks like it works. There is a link to YUP NPM https://www.npmjs.com/package/yup. |
Hey @Master-Daniel I ran into this error just yesterday, and I solved the problem by converting the "is", "then" and "otherwise" clausules into an arrow function that returns the desired value. This would work in your case:
|
@rushmata thanks for the Perfect solution, It works on latest version as well. |
Thanks for the solution i will try it out to confirm
…On Fri, Jan 5, 2024 at 10:28 AM Fernando Mata ***@***.***> wrote:
Hey @Master-Daniel <https://github.com/Master-Daniel> I ran into this
error just yesterday, and I solved the problem by converting the "is",
"then" and "otherwise" clausules into an arrow function that returns the
desired value. This would work in your case:
const settingsFormik = useFormik({ initialValues: { type: '', account: '',
opening_balance: '', account_name: '', account_number: '' },
validationSchema: Yup.object().shape({ type: Yup.string().required('Account
type is required'), account: Yup.string(), // Optional field
opening_balance: Yup.number().typeError('Opening balance must be a
number').required('Opening balance is required else enter 0'),
account_number: Yup.string().when('type', { is: () => 'bank', then: () =>
Yup.string().required('Account number is required'), otherwise: () =>
Yup.string().notRequired(), }), account_name: Yup.string().when('type', {
is: () => 'bank', then: () => Yup.string().required('Account name is
required'), otherwise: () => Yup.string().notRequired(), }) }) })
—
Reply to this email directly, view it on GitHub
<#3923 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ATCOYIAJHB6UT52YQDBGGGTYM7BUXAVCNFSM6AAAAABAFZ4LH2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZYGM3TAMBZGU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
i thought it worked for me too when the condition is true,
EDIT:
|
The validation schema below gave me the error Unhandled Runtime Error TypeError: branch is not a function
const settingsFormik = useFormik({
initialValues: {
type: '',
account: '',
opening_balance: '',
account_name: '',
account_number: ''
},
validationSchema: Yup.object().shape({
type: Yup.string().required('Account type is required'),
account: Yup.string(), // Optional field
opening_balance: Yup.number().typeError('Opening balance must be a number').required('Opening balance is required else enter 0'),
account_number: Yup.string().when('type', {
is: 'bank',
then: Yup.string().required('Account number is required'),
otherwise: Yup.string().notRequired(),
}),
account_name: Yup.string().when('type', {
is: 'bank',
then: Yup.string().required('Account name is required'),
otherwise: Yup.string().notRequired(),
})
})
})
The text was updated successfully, but these errors were encountered: