简体   繁体   English

React material-ui KeyboardDatePicker 和 Formik 不起作用

[英]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和我使用FormikYup进行验证。

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.您可以使用.setFieldValueonChange事件上手动设置值。

 onChange={val => {
      console.log("___", val);
      formik.setFieldValue("dob", val);
 }} 

this method will work in any usecase.此方法适用于任何用例。

只需像这样更改onChange函数:

onChange={(name, value) => formik.handleChange('dob', value)}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM