我正在将材料UI时间选择器与redux表单一起使用,显示的值始终是当前时间,而不是它初始化时使用的值或更新时使用的值。我不确定为什么会这样。我也正在使用material-ui中的日期选择器,并且工作正常。
const renderMUIDatePicker = ({
label,
input,
meta: { touched, invalid, error },
...custom
}) => (
<DatePicker
autoOk
label={label}
placeholder={label}
error={touched && invalid}
helperText={touched && error}
format="YYYY-MM-DD"
{...input}
{...custom}
/>
)
const renderMUITimePicker = ({
label,
input,
meta: { touched, invalid, error },
...custom
}) => {
console.log("STUFF", label, input, custom)
return (
<TimePicker
mode="24h"
ampm={false}
label={label}
format='HH:MM:SS'
placeholder={label}
error={touched && invalid}
helperText={touched && error}
{...input}
{...custom}
/>
)}
<MuiPickersUtilsProvider utils={MomentUtils}>
<Field name="account_valid_from_date" label="Start Date" component={renderMUIDatePicker} className={classes.datepicker} disabled={this.state.disabled} />
<Field name="account_valid_to_date" label="End Date" component={renderMUIDatePicker} className={classes.datepicker} disabled={this.state.disabled} />
</MuiPickersUtilsProvider>
const mapStateToProps = (state, props) => {
if(Object.keys(state.editUsers).length === 0) return {}
return {
initialValues: {...state.editUsers.editUser.users, ...state.editUsers.editUser.user_attributes }
}
}
export default connect(
mapStateToProps
)(reduxForm({
form: 'editUser', // a unique identifier for this form
enableReinitialize: true,
})(EditUser))
这是注销的内容:
name: "login_constrained_by_end_time"
onBlur: ƒ (event)
onChange: ƒ (event)
onDragStart: ƒ (event)
onDrop: ƒ (event)
onFocus: ƒ (event)
value: "11:08:22"
className: "EditUser-datepicker-340"
disabled: false