我正在尝试使用 redux-form-material-ui 渲染表单的初始值。到目前为止,initialValues 适用于我的 TextField 组件,但不适用于 SelectField。
我目前正在通过父组件将initialValues作为 Prop 传递,如下所示:
<PacketFilterForm initialValues={this.props.initialConfigValuesForForm} />
正在处理此案例:
<Field name="name" component={TextField} hintText="Ex. Rule 1" floatingLabelText='Name of Rule'/>
但是,它不适用于这种情况:
<Field component={SelectField} name='ethertype'>
<MenuItem key={1} value='ipv4' primaryText="IPV4" />,
<MenuItem key={2} value='ipv6' primaryText="IPV6" />
</Field>
如何为此 SelectField 组件设置初始值?
最佳答案
尝试使用您的componentWillMount()
,因为redux form
的Form
组件使用名称和值
componentWillMount() {
this.props.change('ethertype', 'ipv6')
}
关于reactjs - 无法使用 redux-form-material-ui 在 SelectField 组件上设置初始值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48774676/