Reactjs redux表单:单击更改特定字段值
如何更改事件上特定字段的值 示例不工作(无法读取未定义的属性“firstname”)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()">
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>
);
}
}