Skip to content
Advertisement

Set autocomplete off for Formik field

To set the autocomplete off for a simple input it must be done like this: <input type="text" autocomplete="off">

In this case, there is a Formik Field and the input looks like this:

<Field
  className="my-class"
  name="myValues"
  as={Input}
  placeholder="Write something"
/>

and it seems that adding autocomplte="off" doesn’t work in this case:

<Field
  className="my-class"
  name="myValues"
  as={Input}
  placeholder="Write something"
  autocomplete="off"
/>

Any ideas?

Advertisement

Answer

I am not sure where you are doing wrong. You can simply do this:

 <label>
              <Field name="picked" value="One" autocomplete="off" />
              One
            </label>

According to doc if you don’t pass anything it will treat as a input

Here is the demo:https://codesandbox.io/s/happy-khayyam-9mdll?file=/index.js

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement