redux-form-material-ui
redux-form-material-ui copied to clipboard
Setting a value on a selectField
OK, I've read the readme, so I know that defaultValue won't work but I can't set a value on the selectField even using the value prop:
<Field
name={`service_${index}`}
component={SelectField}
hintText="Select a service"
value={0} // <-- here
children={serviceOptions}
/>
Is that expected behaviour?
(serviceOptions look like:)
const serviceOptions = services.map(serviceOption => (
<MenuItem
key={serviceOption.id}
value={serviceOption.id} // <-- first one will be 0
primaryText={serviceOption.name}
style={{
textAlign: 'left',
}}
/>
));
I thought that if the value on the SelectField matched a value on a MenuItem, then it would select that item? Am I wrong about that??
Thanks
Redux form has a special way of handling controlled component's initial state. You must use the reduxForm HOC's initialValues field instead.
reduxForm({
name: 'myForm',
initialValues: {
'service_1': 0
}
})(MyFormComponent)