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?
moment(undefined)
results in current date. This equals to setting the default value to current date. UsegetValueProps={(i) => ({ value: i === undefined ? undefined : moment(i) })}
instead. – Quay