jaredpalmer / formik

Build forms in React, without the tears 😭
https://formik.org
Apache License 2.0
33.96k stars 2.79k forks source link

Masked input not working #1307

Closed prateek3255 closed 3 years ago

prateek3255 commented 5 years ago

🐛 Bug report

I am using a masked input for entering DOB from user, it works fine outside formik, but is not working at all in formik.

<MaskedInput
    mask={[/\d/, /\d/, '/', /\d/, /\d/, '/', /\d/, /\d/, /\d/, /\d/]}
    appearance={isDobInvalid(value) ? 'error' : 'normal'}
    name="dob"
    onChange={handleChange}
    placeholder="DD/MM/YYYY"
    guide={false}
    type="text"
    value={values.dob}
    render={(ref, props) => (
      <TextField
        error={{
          [ERRORS.dateInvalid]: isDobInvalid(value),
        }}
        label="Date of Birth"
        name="dob"
        innerRef={ref}
        value={values.dob}
        {...props}
      />
    )}
  />

Current Behavior

Mask is not working at all, I am able to enter all alphanumeric values to the input. The '/' after entering the number is also not being added automatically

Expected behavior

It should work as it does outside formik

package information

Software Version(s)
Formik 1.4.2
React 16.6.3
Browser chrome 70
npm/Yarn 6.4.1
Operating System windows 10 v1709
jaredpalmer commented 5 years ago

Without a reproducible example it’s hard to know for sure what is going on. Would you be able to create a codesandbox so I can take a look? Also, please fill out the package information section of the bug report template so we can know which version of Formik you are using.

Potentially relevant #610

prateek3255 commented 5 years ago

Here is a sandbox, https://codesandbox.io/s/0mn9p1r87p but I am getting a CORS error in it though.

jaredpalmer commented 5 years ago

Your mask is causing the CORS issue, can you simplify it for the purposes of the demo?

prateek3255 commented 5 years ago

How exactly do I simplify it, to remove the CORS error I would have to remove the library?

Andreyco commented 5 years ago

Here is another example for masking of input value. It handles SSN in 000-00-0000 format https://codesandbox.io/s/4rkyylp24w

wallynm commented 5 years ago

In the future, <Field component={Input}/> gonna be deprecated but we're currently using this way:

https://codesandbox.io/s/formik-react-text-mask-mxmru

maddhruv commented 3 years ago

Closing due to long inactivity