在 antd design react 中使用 DatePicker 和 Form FormItem [英] Using DatePicker with Form FormItem in antd design react
本文介绍了在 antd design react 中使用 DatePicker 和 Form FormItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<FormItem {...formItemLayout} label="Publish Date">
{getFieldDecorator('publishDate', {
initialValue: '',
rules: [
{
required: false,
message: 'Please input publishDate',
whitespace: true,
},
],
})(<DatePicker onChange={onChange} />)}
</FormItem>
不起作用.我收到异步验证器说publishDate 不是字符串".
doesn't work. I get async validator saying 'publishDate is not a string'.
所以我以这种方式使用它作为临时解决方案.
so I'm using it this way as a temporary solution.
<FormItem {...formItemLayout} label="Publish Date">
{getFieldDecorator('publishDate', {
initialValue: getCurrentDate(),
rules: [
{
required: false,
message: 'Please input publishDate',
whitespace: true,
},
],
})}
<DatePicker onChange={onChange} />
</FormItem>
有什么帮助吗?提前致谢!
any help ? thanks in advance!
推荐答案
应该在规则中使用type: 'object'
<FormItem {...formItemLayout} label="Publish Date">
{getFieldDecorator('publishDate', {
initialValue: moment(),
rules: [
{
type: 'object',
required: false,
message: 'Please input publishDate',
whitespace: true,
},
],
})(<DatePicker/>)}
</FormItem>
此外,您不需要 onChange
处理程序.
Also, you wouldn't need onChange
handler.
这篇关于在 antd design react 中使用 DatePicker 和 Form FormItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文