Leo Messi
Leo Messi

Reputation: 6166

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?

Upvotes: 5

Views: 11563

Answers (4)

Manish Patil
Manish Patil

Reputation: 21

Add enableReinitialize in Formik, It is working for me.

Upvotes: 0

react user
react user

Reputation: 41

Solution: camelCase.

Instead of autocomplete='off', use autoComplete='off'.

Upvotes: 4

ananda singh
ananda singh

Reputation: 1

<Field
    name="password"
    type="password"
    component={() =>
        <input
            className="form-control"
            type="password"
            autoComplete="new-password"
        />
    }
/>

Upvotes: 0

Shubham Verma
Shubham Verma

Reputation: 5054

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

Upvotes: 3

Related Questions