简体   繁体   中英

How to validate office-fabric ui DatePicker

I have used Office fabric UI date-picker component and want to show validation message on click of form submit button. Wants to show custom validation messages like "Mandatory field" etc.

Please suggest how to implement it or is there an attribute provided by fabric UI for date-picker validation?

code:

<DatePicker
  className={style}
  label={form.colText}
  showMonthPickerAsOverlay={showMonthPickerAsOverlay}
  onSelectDate={onSelectionChange}
  isRequired={form.mandatory}
  allowTextInput={allowTextInput}
  isMonthPickerVisible={false}
  formatDate={pattern ? date => onFormatDate(date, pattern) : null}
  maxDate={new Date()}
  value={form.value}
  placeholder={messages.datePickerPlaceholder}
/>;

Try to use Redux-form. Create a wrap component.

https://redux-form.com/8.3.0/docs/api/field.md/

Something like below:

<Field name={"startDate"}
       label={"Start date"}
       placeholder={"Select a date"}
       validate={[isRequired]}
       component={DatePicker} />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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