简体   繁体   中英

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.

<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 value={moment()} style={{ width: '100%' }} />

Is this a problem with getValueProps prop?

I fixed it!

In case that anyone has same issue:

you have to change getValueProps to something like this:

getValueProps={(i) => ({value: moment(i)})}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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