Giter Club home page Giter Club logo

Comments (4)

PatrycjuszNowaczyk avatar PatrycjuszNowaczyk commented on June 7, 2024

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.

from formik.

rushmata avatar rushmata commented on June 7, 2024

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:

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(),
            })
        })
    })

from formik.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.