简体   繁体   English

Ant 在表单中设计DatePicker

[英]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.我在表单中使用来自antdDatePicker组件,并想更改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.

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