I'm creating a form with material-ui
and I'm using Formik
and Yup
for validation.
The TextField components work perfectly, however, the KeyboardDatePicker
component presented the following error in the console
_onChange is not a function
and is now presenting
type is undefined.
Below is a cbs with the code. https://codesandbox.io/s/agitated-dust-wf6fn
Formik can be easily used/integrated with Material UI, with just passing a few formik props to the respective Material UI Component props.
How to use React Material UI's Autocomplete component with Formik? To use React Material UI's Autocomplete component with Formik, we can call Formik's setFieldValue function with the name prop value of the Autocomplete and the value that is selected. We add the Form component with the Autocomplete component inside.
First, create a new react application, react-formik-app using Create React App or Rollup bundler by following instruction in Creating a React application chapter. Next, install the Formik library. Next, open the application in your favorite editor. Next, create src folder under the root directory of the application.
you can use .setFieldValue
to set value manually on onChange
event.
onChange={val => {
console.log("___", val);
formik.setFieldValue("dob", val);
}}
this method will work in any usecase.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With