React Datepicker with redux-form

橙三吉。 提交于 2019-12-04 21:16:05

you have to make a custom component to validate and use datepicker with redux-form

Try this

const datePicker = ({ input, label, type, className, selected, meta: { touched, error } }) => (
      <div>
        <div>
          <DatePicker {...input}
            selected={selected} placeholder={label}
            type={type} className={className}
            peekNextMonth
            showMonthDropdown
            showYearDropdown
            dropdownMode="select"
          />
          {touched && error && <span className="error_field">{error}</span>}
        </div>
      </div>
    )

and then pass props to that custom component

          <Field
            name="date_of_birth"
            component={datePicker}
            type="text"
            selected={this.state.date_of_birth}
            onChange={this.handleChange.bind(this)}
            className="form-control"
          />

For future readers, just go to this link: DatePicker in Redux Form

first, I created the component like metioned in link above and just passed the selected prop in it. in my case:

<Field
             name="due_date"
             component={DatePickerComponent}
             selected={this.state.date_of_briefing} />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!