Javascript 以编程方式更改Redux表单字段值

Javascript 以编程方式更改Redux表单字段值,javascript,reactjs,redux,redux-form,Javascript,Reactjs,Redux,Redux Form,当我使用redux formv7时,我发现无法设置字段值。现在在我的表单中,我有两个选择组件。当第一个选择组件值更改时,第二个的值将被清除 类内渲染: <div className={classNames(style.line, style.largeLine)}> <div className={style.lable}>site:</div> <div className={style.content}> <Field

当我使用
redux form
v7时,我发现无法设置字段值。现在在我的
表单中,我有两个
选择组件。当第一个
选择
组件值更改时,第二个的值将被清除

类内渲染:

<div className={classNames(style.line, style.largeLine)}>
  <div className={style.lable}>site:</div>
  <div className={style.content}>
    <Field
      name="site"
      options={sites}
      clearable={false}
      component={this.renderSelectField}
      validate={[required]}
    />
  </div>
</div>

<div className={classNames(style.line, style.largeLine)}>
  <div className={style.lable}>net:</div>
  <div className={style.content}>
    <Field
      name="net"
      options={nets}
      clearable={false}
      component={this.renderSelectField}
      validate={[required]}
      warning={warnings.net}
    />
  </div>
</div>

您可以在
this.handleSelectChange({value,type:input.name})中使用onChange逻辑
并使用

根据文件:

更改(字段:字符串,值:任意):函数

更改的值 Redux存储中的字段。这是一个绑定动作的创建者,所以 不返回任何内容

代码:


是否有一个API可以同时设置多个字段?在initialValueshow期间,此操作不适用于
组件的
组件='select'
变体?@Dane类似于它对输入字段的工作方式,它需要字段名作为第一个参数,并且需要从“redux form”中选择
导入{change}选项的值
如果从
redux form
导入
change
,则参数为:
change(form:string,field:string,value:any,touch?:boolean,persistentSubmitErrors?:boolean):FormAction
renderSelectField = props => {
  const {
    input,
    type,
    meta: { touched, error },
    ...others
  } = props
  const { onChange } = input
  const _onChange = value => {
    onChange(value)
    this.handleSelectChange({ value, type: input.name })
  }
  return (
    <CHSelect 
      error={touched && error}
      {...input}
      {...others}
      onChange={_onChange}
      onBlur={null}
    />
  )
}
import { change } from "redux-form";

handleSelectChange = (value, type) => {
  if (type === "site") {
    this.props.change('net', "newValue");
  }
}

const mapDispatchToProps = (dispatch) => {
  return bindActionCreators({change}, dispatch);
}