Skip to content

Can use array of validators in validate props#2326

Open
hamcher wants to merge 1 commit into
jaredpalmer:mainfrom
hamcher:multi-validation-feature
Open

Can use array of validators in validate props#2326
hamcher wants to merge 1 commit into
jaredpalmer:mainfrom
hamcher:multi-validation-feature

Conversation

@hamcher

@hamcher hamcher commented Feb 28, 2020

Copy link
Copy Markdown

can use multi validations in field level validations

for example

const email = (value) => { 
    if (!yup.string().email().isValidSync(value)) {
      return 'Invalid email'
    } 
}

const required = (value) => { 
    if (!yup.string().required().isValidSync(value)) {
      return 'Field required'
    } 
}

<form>
     <TextField
        name="email"
        validate={[required(), email()]}
    />
    <TextField
        name="password"
        type="password"
        validate={required()}
    />
</form>

@vercel

vercel Bot commented Feb 28, 2020

Copy link
Copy Markdown

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/jared/formik-docs/7zp60iolt
✅ Preview: https://formik-docs-git-fork-hamcher-multi-validation-feature.jared.now.sh

@codesandbox-ci

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 01c7002:

Sandbox Source
Formik TypeScript Playground Configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant