Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs redux表单:单击更改特定字段值_Reactjs_Redux_Redux Form - Fatal编程技术网

Reactjs redux表单:单击更改特定字段值

Reactjs redux表单:单击更改特定字段值,reactjs,redux,redux-form,Reactjs,Redux,Redux Form,如何更改事件上特定字段的值 示例不工作(无法读取未定义的属性“firstname”) onclick1(){ this.props.fields.firstname.onChange(“约翰”) } render(){ const{handleSubmit}=this.props; 返回( 给约翰起名 可以 这个解决方案是在这里提出的,但对我不起作用 redux form v7我发现您的代码中存在一些问题: <button onClick="this.onclick1()">

如何更改事件上特定字段的值

示例不工作(无法读取未定义的属性“firstname”)

onclick1(){
this.props.fields.firstname.onChange(“约翰”)
}
render(){
const{handleSubmit}=this.props;
返回(
给约翰起名
可以
这个解决方案是在这里提出的,但对我不起作用


redux form v7

我发现您的代码中存在一些问题:

<button onClick="this.onclick1()"> 

请注意,我只重写了你代码的一些相关部分,我使用的是标准的
输入组件,因为我不知道你的
文本字段
是什么样子。查看在线演示

你的表单是什么样子的?你会分享一些代码吗?@Dario更新示例
<button onClick="this.onclick1()"> 
<button onClick={this.onclick1}>
class ComplexForm extends React.PureComponent {
  constructor(props) {
    super(props);
    this.onclick1 = this.onclick1.bind(this);
  }

  onclick1() {
    this.props.change("firstname", "John");
  }

  render() {
    const { handleSubmit } = this.props;
    return (
      <form onSubmit={handleSubmit}>
        <Field name="firstname" component="input" label="first name" />
        <button onClick={this.onclick1}>Set name to John</button>
      </form>
    );
  }
}