Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
badie21 opened this issue Dec 17, 2020 · 3 comments
Closed

Comments

@badie21
Copy link

badie21 commented Dec 17, 2020

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 badie21 closed this as completed Dec 17, 2020
@badie21 badie21 reopened this Dec 17, 2020
@badie21
Copy link
Author

badie21 commented Dec 17, 2020

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
Copy link

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
Copy link

AliAmini commented Mar 14, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants