reactjs - 无法使用 redux-form-material-ui 在 SelectField 组件上设置初始值

标签 reactjs redux redux-form

我正在尝试使用 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 formForm组件使用名称和值

componentWillMount() {
    this.props.change('ethertype', 'ipv6')
}

关于reactjs - 无法使用 redux-form-material-ui 在 SelectField 组件上设置初始值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48774676/

相关文章:

reactjs - 高阶组件被多次调用

javascript - 基于其他Select字段选择ant design更新Select Option列表

javascript - 如果 SweetAlert 隐藏,则正在呈现

javascript - React & Redux-Form - 当第一个请求尚未解决时防止表单重复请求

javascript - 我可以在 React + Redux 中使用 Props 设置初始状态吗?

reactjs - 在 TextField 类型 ="number"上设置最小值/最大值?

validation - 使用 redux-form 和 Fetch API 进行服务器验证

javascript - 如何将焦点设置为在循环中动态创建的渲染 redux 表单

node.js - ReactJS 发送 GET 请求,响应 302 重定向,收到 CORS 错误

react-native - 远程 redux devtools 停止工作