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
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.
Here is the sand box demo for the same
https://codesandbox.io/s/formik-material-ui-date-picker-with-yup-validate-f3mdp
只需像这样更改onChange
函数:
onChange={(name, value) => formik.handleChange('dob', value)}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.