saeedrahimi / antd-jalali

A wrapper for ant-design date picker and calendar to support Jalali calendar type
https://saeedrahimi.github.io/antd-jalali/
83 stars 36 forks source link

antd-jalali datepicker problem when setting initial value via form instance #8

Closed badie21 closed 2 years ago

badie21 commented 3 years ago

when i'm trying to set initial value for jalali datepicker via form.setFieldsValue the datepicker popup container goes crazy and i can't figure the problem and you can not select a date until you choose the today date and then it is possible to choose date Screenshot (22)

this is the part of my code that i'm trying to set datePicker initial value

form.setFieldsValue({

        date: moment(DATE, 'YYYY-MM-DD'),
      })
 <Form.Item name="date" label="تاریخ قرارداد" labelCol={{ span: 24 }}>
                <JalaliDatePicker
                  format="YYYY-MM-DD"
                  style={{ width: '100%' }}
                />
              </Form.Item>
badie21 commented 3 years ago

i used day.js to get the object of date and then set that as initial value

date: dayjs(
          Jmoment.from(selectedField.contract.datetime, 'YYYY-MM-DD')
            .locale('fa')
            .format('YYYY-MM-DD'),
        ).locale('fa')
mehdi-ard commented 3 years ago

i used day.js and jalaliday for initial value :

const date = dayjs(date).calendar('jalali').locale('fa')

 <DatePickerJalali
format={'YYYY/MM/DD'}
value={date }
/>
AliAmini commented 3 years ago

Hi Saeed

Are you sure that default value will work with dayjs object? I try it in different ways, but I didn't get any hopeful results.

When you set default value with dayjs object, it will throw:

TypeError: clone.weekday is not a function

Because clone().weekday() is a function of moment, not dayjs. I think you did wrong.

Currently, the only way of setting default value is moment. But when the value set by moment, it goes crasy because you mixed up moment and dayjs.

Can you set a default value in your demo page?