更新 redux 表单上的值

Update a value on redux form

我有一个 react-bootstrap class 的表格。代码是这样的:

class MyReactClass extends Component {

// ....

render() {

    return (
        <div>

<Field name="combobox1" component={ComboBox} options={options} ></Field>
<Field name="textField2" component={My_TextField}></Field>
<Field name="textField3" component={My_TextField}></Field>
<Field name="textField4" component={My_TextField}></Field>
       </div>
   }
}


export default reduxForm({
    form: 'myReactClass ',
  }
)(MyReactClass );

我添加了一个初始化来初始化一些值:

componentDidMount() {
    this.props.initialize({textField2:'blabla'});
  }

现在我希望当用户从组合框中选择一个值时,它会自动更改 textfield3 的值。我有一个用于组合框的 WORKING onChange 函数,但我找不到更改 textfield3 值的方法。我再次尝试使用 "initialize" - this.props.initialize({textField3: this.getUpdatedValue()}); 但它初始化了整个表单,表单被清除并且只有 textfield3 的值。

我试图访问 this.props.textField3 但我得到了 undefined

如何更新表单的值?

this.props.change('textField3', this.getUpdatedValue()) 可以。

可选,如果您需要用户了解该值是自动填充的但可以手动更改,您可以使用:

this.props.autofill('textField3', this.getUpdatedValue())

这些在文档中有描述here