简体   繁体   English

antd datepicker 使用 formik 预填充值

[英]antd datepicker prepopulate value with formik

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.我有一个 formik 表单,其中 antd 日期选择器在我用来创建条目时工作正常,但在编辑的情况下,我必须预先填充日期选择器。 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>

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.在预先填充 antd 日期选择器的情况下使用 value prop 修复它...如果您不必预先填充日期选择器,则不需要添加 value prop。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM