【发布时间】:2019-03-11 18:19:24
【问题描述】:
我有一个注册表单。当用户接受服务条款时,他点击一个选中复选框的按钮。当他点击拒绝时,此按钮取消选中复选框。
我读过this answer to programmatically change redux-form values。我可以更改除复选框以外的任何字段。
这是我的代码:
class RegisterContainer extends Component {
constructor(props) {
super(props);
this.state = {
modalTOS: false
};
this.accept = this.accept.bind(this);
this.decline = this.decline.bind(this);
this.toggleTOSModal= this.toggleTOSModal.bind(this);
}
accept() {
this.props.actions.change("register", "email", "foo42bar"); //This is a working test
this.props.actions.change("register", "read", true);
this.toggleTOSModal();
}
decline() {
this.props.actions.change("register", "read", false);
this.toggleTOSModal();
}
// ....
我添加此行只是为了检查是否可以更改电子邮件值:
this.props.actions.change("register", "email", "foo42bar");
有效!
一步一步,我尝试了很多选项来检查,但没有人改变复选框:
this.props.actions.change("register", "read", "on");
this.props.actions.change("register", "read", true);
this.props.actions.change("register", "read", "1");
this.props.actions.change("register", "read", 1);
this.props.actions.change("register", "read", "true");
this.props.actions.change("register", "read", "a");
在验证器中,我添加了一些 console.error 。通过手动检查或通过接受按钮,值为 true。但是 Checkbox 不勾选
编辑:我的字段声明:
<Field name="read" component={FormCheckBoxGroup} {...fieldProps} onClick={onClickTos} required />
FormCheckBoxGroup:
<FormGroup check>
<Col sm={{ size: 8, offset: 4 }}>
<Label check className={className}>
<Input {...input} type="checkbox" disabled={disabled} required={required} />
{label}
</Label>
{!required && helpBlock && <HelpBlock>{helpBlock}</HelpBlock>}
{error && <HelpBlockErrors errors={messages} />}
{children}
</Col>
</FormGroup>
有人有想法吗?
【问题讨论】:
标签: javascript reactjs redux-form