-
I am trying to implement an Autocomplete field into my Formik form, however I cannot get the touched property to fire on the autocomplete. I have tried using the <Formik
initialValues={{
name: '',
...
autocomplete: '',
}}
...
>
{({ dirty, errors, isSubmitting, touched, values }) => console.log(JSON.stringify(touched) || (
...
<Field
component={Autocomplete}
options={options.map(({ label }) => label)}
sx={{ width: 300 }}
onChange={(e, value) => onChange(value)}
renderInput={(params) => (
<TextField
{...params}
name="autocomplete"
id="autocomplete"
label="Autocomplete"
error={Boolean(touched.autocomplete && errors.autocomplete)}
helperText={touched.autocomplete && errors.autocomplete}
/>
)}
/> Should we by binding to the Autocomplete component itself or to the TextField inside of the autocomplete? |
Beta Was this translation helpful? Give feedback.
Answered by
mikeymop
Nov 5, 2021
Replies: 1 comment 4 replies
-
I ended up getting this to work. |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
mikeymop
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I ended up getting this to work.
You need to pass formik's
handleBlur
into the Autocomplete'sonBlur
prop.