react-redux-form
or redux-form
?
messages.isRequired
supplied to Errors
"
class DatePickerInput extends Component {
constructor (props) {
super(props)
this.state = {
startDate: props.value ? moment.unix(props.value) : ''
};
this.handleChange = this.handleChange.bind(this);
}
handleChange(date) {
this.setState({
startDate: date
});
this.props.onChange(date)
}
render() {
return <DatePicker
name={this.props.name}
className="form-control"
dateFormat="DD MMM YYYY"
locale="ru-ru"
readOnly={true}
selected={this.state.startDate}
onChange={this.handleChange}
minDate={this.props.minDate}
maxDate={this.props.maxDate}
placeholderText="Выберите дату"
/>;
}
}
export default class DatePickerControl extends Component {
customInput(props) {
return (<DatePickerInput {...props}/>);
}
render() {
return (
<div className="form-group">
{ this.props.label &&
<label className="control-label" htmlFor={this.props.id}>{this.props.label}</label>}
<Control {...this.props} className="form-control" component={this.customInput} getValue={(moment) => {
return parseInt(isNaN(parseInt(moment)) ? moment.format("X") : moment);
}}/>
</div>
);
}
}
Hello everyone! I'm fairly new to react and redux and my team is currently using react-redux-form. I have a question but there is some context before I ask.
I have a form, say the model is 'team', that will make a request to retrieve all data from the db, say 'users', when the component mounts. This users data will have a list of id's and a names. I will map over the names over a dropdown list using the Control.select and the model will point be "team.user.name".
So what I want to do is use the id to pass in with every option because my model needs the "team.user.id" to save to the db on submit. How is this done?
const required = () => ({ validator: (val) => (val && val.length) });
<Control
validators: { required: required().validator }
/>