[英]React material-ui KeyboardDatePicker and Formik not working
I'm creating a form with material-ui
and I'm using Formik
and Yup
for validation.我创建一个表单
material-ui
和我使用Formik
并Yup
进行验证。
The TextField components work perfectly, however, the KeyboardDatePicker
component presented the following error in the console TextField 组件工作正常,但是,
KeyboardDatePicker
组件在控制台中出现以下错误
_onChange is not a function
_onChange 不是函数
and is now presenting现在正在展示
type is undefined.
类型未定义。
Below is a cbs with the code.下面是带有代码的 cbs。 https://codesandbox.io/s/agitated-dust-wf6fn
https://codesandbox.io/s/agitated-dust-wf6fn
you can use .setFieldValue
to set value manually on onChange
event.您可以使用
.setFieldValue
在onChange
事件上手动设置值。
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 https://codesandbox.io/s/formik-material-ui-date-picker-with-yup-validate-f3mdp
只需像这样更改onChange
函数:
onChange={(name, value) => formik.handleChange('dob', value)}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.