I’m having a weird bug on my React form and the username and the password gets filled automatically when I go to that page.
My Input
component:
return (
<div
className={
error ? [styles.form_group, styles.error].join(" ") : styles.form_group
}
>
{placeholder && (
<div
ref={refPlaceholder}
className={styles.placeholder}
style={props.defaultValue ? { display: "none" } : null}
>
<label htmlFor={name} className={styles.label}>
{placeholder}
</label>
{props.required && <span className={styles.star}>*</span>}
</div>
)}
<input
ref={refFormControl}
{...propsInput}
autoComplete="off"
className={styles.form_control}
name={name}
/>
{error && (
<span ref={refFormError} className={styles.error}>
{error}
</span>
)}
</div>
);
and I’m just using it in div
like:
<div>
<Input
id="username"
type="text"
name="username"
placeholder="Username"
error={getInputError(errors, "username")}
onChange={(e) => onChangeFormValue("username", e.target.value)}
/>
</div>
Values of username and password gets filled automatically.
I have tried following, but none worked:
- add
form
and set it toautoComplete: 'off'
autoComplete='new-password'
- added
hidden
input value on top ofform
, but didn’t work either
2
Answers
You have to wrap the input tag into the form:
Also, you can try
HTML’s tags are not case sensitive, but attributes are.
In your code you have
autoComplete="off"
with a capital letter C.Try with
autocomplete="off"
(all lower-case).