Redux-form-material-ui: Setting a value on a selectField

Created on 10 Jul 2017  路  1Comment  路  Source: erikras/redux-form-material-ui

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

Most helpful comment

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)

>All comments

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)
Was this page helpful?
0 / 5 - 0 ratings