[英]Ant design DatePicker in form
I'm using DatePicker
component from antd
inside a form and want to change the default onChange
and value
of props in DatePicker
but it is not working.我在表单中使用来自
antd
的DatePicker
组件,并想更改DatePicker
中的默认onChange
和道具value
,但它不起作用。
<Form.Item
label='Test Label'
name='startDate'
getValueFromEvent={(onChange) => moment(onChange).format('YYYY-MM-DD')}
getValueProps={(i) => moment(i)}
>
<DatePicker format='YYYY-MM-DD' style={{ width: '100%' }} />
</Form.Item>
When I use DatePicker
outside of the form it works:当我在表单之外使用
DatePicker
时,它会起作用:
<DatePicker value={moment()} style={{ width: '100%' }} />
Is this a problem with getValueProps
prop?这是
getValueProps
道具的问题吗?
I fixed it!我修好了它!
In case that anyone has same issue:如果有人有同样的问题:
you have to change getValueProps
to something like this:您必须将
getValueProps
更改为如下所示:
getValueProps={(i) => ({value: moment(i)})}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.