0
votes

I have a formik form in which antd date picker is working fine when i use to create an entry but in case of edit, I have to pre-populate the date picker. The pre-populate method for input and other fields is not working with date picker. Please help me if you can. Thankyou

below is the sample code for the field

<section className="date-picker-wrapper">
                                <CustomDatePicker
                                  classes={
                                    touched.dateValue && errors.dateValue
                                      ? "error-field"
                                      : ""
                                  }
                                  onChange={(date, dateString) => {
                                    setFieldValue("dateValue", dateString);
                                  }}
                                  handleBlur={() =>
                                    setFieldTouched("dateValue", true)
                                  }
                                  selectedDates={monthlyMenuState.disabledDates}
                                  disabled={editForm ? true : false}
                                />

                                {touched.dateValue && errors.dateValue ? (
                                  <div className="error-label">
                                    {errors.dateValue}
                                  </div>
                                ) : null}
                              </section>
1

1 Answers

0
votes

fixed it using value prop in case of pre-populating the antd date picker...You don't need to add value prop in case you don't have to pre-populate the date picker.

value={value ? moment(value, "YYYY-MM-DD") : ""}