DatePicker in Redux Form

谁说胖子不能爱 提交于 2019-11-29 04:28:19

You want to wrap the DatePicker element that it can be used as a component on "Field" like this:

const renderDatePicker = ({input, placeholder, defaultValue, meta: {touched, error} }) => (
  <div>
        <DatePicker {...input} dateForm="MM/DD/YYYY" selected={input.value ? moment(input.value) : null} />
        {touched && error && <span>{error}</span>}
  </div>
);

export default renderDatePicker

Refer to this GitHub issue for more information: https://github.com/Hacker0x01/react-datepicker/issues/543

export const renderDatePicker = ({ input, label, meta: { touched, error }, ...custom }) => {
    return (
        <DatePicker {...input} {...custom} autoOk={true} dateForm='MM/DD/YYYY' onChange={(event, value) => input.onChange(value)} />
    );
};
export const Datepicker = ({

input, id, label, required, className, disabled, intl, popoverAttachment, popoverTargetAttachment, popoverTargetOffset, todayButton,
meta: { touched, error, invalid } }) => (
    <FormGroup color={`${touched && invalid ? 'danger' : ''}`} className={`${required ? 'required ' : ' '}${className}`}>
        {label && <Label htmlFor={id}>{label}</Label>}
        <DatePicker
            className="form-control"
            {...input}
            fixedHeight
            todayButton={todayButton}
            label={label}
            id={id}
            dateForm="MM/DD/YYYY"
            selected={input.value ? moment(input.value) : null}
            disabled={disabled}
            popoverAttachment={popoverAttachment}
            popoverTargetAttachment={popoverTargetAttachment}
            popoverTargetOffset={popoverTargetOffset}
        />
        {touched && error && <FormFeedback>{intl.formatMessage(error)}</FormFeedback>}
    </FormGroup>
);

You can make your own component field of datepicker like i mentioned above and used it in Field of redux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!