Skip to content

validationSchema not working after page reload #3989

Open
@sgarchavada

Description

Bug report

Current Behavior

I am just simply adding max value validation, which is working fine for the first time, but when I reload the page, and typing again, validation is not applying.

Expected behavior

validation should work after the page reload also.

Reproducible example

import { Formik } from 'formik';
import * as Yup from 'yup';
import TextInput from '../common/TextInput';

const DebitCard = () => {
  const validateSchema = Yup.object().shape({
    cardNo: Yup.string()
      .max(5, 'Must be exactly 5 characters')
      .required('Required')
  })

  return (
    <>
      <Formik
        initialValues={{
          cardNo: '',
        }}
        validationSchema={validateSchema}
        onSubmit={values => {
          alert(JSON.stringify(values, null, 2));
        }}
      >
          <form >
            <div className="flex space-x-5 mt-3">
              <TextInput
                label="Card Number"
                name="cardNo"
                type="number"
               />
          </form>
      </Formik>
    </>
  )
}

export default DebitCard;

Suggested solution(s)

Additional context

It only happen for the first time, if I unfocus the input it started showing the validation error, second time its working fine without loosing focus on input

Your environment

Software Version(s)
Formik ^2.4.6
React ^1
TypeScript ^5
Browser Chrome
npm/Yarn npm
Operating System Window 11

Activity

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

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions