New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting setFieldValue to undefined doesn't clear text input #2180
Comments
I'm not sure about your use case but you can try giving an empty string. |
I also faced the same issue, instead it changes the value attribute of the html input element by it doesn't update the UI |
Are there any solutions or work arounds for this issue? |
@ShaunKT this is expected behavior. Setting an input's value to undefined sets the input's |
@ShaunKT A simple workaround is to call |
You can also create your own version of Field which does something like: const TextInput = (fieldProps) => {
const [field] = useField(fieldProps);
return <input {...field} value={field.value ?? ''} />
} Or in v3 you can do: const formatString = (value) => value ?? '';
const MyForm = () => (
<Formik {...props}>
<Field name="myField" format={formatString} />
</Formik>
) |
Use |
Yup didn't like using |
🐛 Bug report
Current Behavior
When calling
setFieldValue('name', undefined)
, Formik correctly deletes the value from the state but doesn't update the Field value.Expected behavior
Should clear the text input value.
Reproducible example
https://codesandbox.io/s/formik-setformvalue-to-undefined-doesnt-clear-input-dgqtu
Suggested solution(s)
🤷♂️
Additional context
N/A
Your environment
The text was updated successfully, but these errors were encountered: