3

I have the following problem:

I am using ant.design in version 5.2.0. When I use the component as follows, I always get the attached error message when I pass a date to for the Form.Item in dayjs format: enter image description here

If I don't specify the default value as dayjs <form> I don't get an error, but I also don't get a prefilled value in the datepicker.

What else can I try?

Here is an excerpt of the source code:

<Form
    form={formRef}
    onFinish={handleSubmit}
    initialValues={{...collaboration, dueDate: dayjs(collaboration.dueDate)}}
>
    <Form.Item label="DatePicker" name={"dueDate"} rules={[{ required: true, message: 'Please select time!' }]}>
         <DatePicker style={{width: "100%"}}/>
    </Form.Item>
</Form>
halfer
  • 19,824
  • 17
  • 99
  • 186

4 Answers4

0

Here is a sandbox for this case: https://codesandbox.io/s/antd-reproduction-template-forked-4mv33s?file=/index.js

Edit: It works in the sandbox :D

0

Here is my code ** it is working for me ** antdesign v5

  • datepicker of form values will not accept string;
const dateFormat = "DD-MM-YYYY";

const init = {
    dateOfBirth: dayjs(),
  };

<Form
   layout="vertical"
   hideRequiredMark
   onFinish={(values) => console.log(values)}
   initialValues={init}
 >
    <Form.Item label="Date Of Birth" name="dateOfBirth">
       <DatePicker format={dateFormat} />
    </Form.Item>
 </Form>
Yewin
  • 160
  • 1
  • 7
0

I get the same error when I was trying to set a string value to Datepicker:

I had to convert my dates string using dayjs:

 import dayjs from 'dayjs';
 ...
 
 for(let field of date_fields){
    values[field] = values[field]? dayjs(values[field]):null;
 }
 form.setFieldsValue(values);
Adán Escobar
  • 1,729
  • 9
  • 15
0

For me, in table columns config, when I change the key value from createdAt to created_at, it throws this error.

However I can change it to created_at_123. Some values may be used internally by the component. It is not mentioned in the docs.

enter image description here

shrekuu
  • 1,716
  • 1
  • 23
  • 38