【发布时间】:2016-06-05 19:18:59
【问题描述】:
我在 angular2 的注册表单中添加了一个 recaptcha。 我有一个控制器来匹配 recaptcha 和所需的验证器。
this.captchaControl = fb.control(false, Validators.required);
this.userForm = fb.group({
...
captchaControl: this.captchaControl
});
当用户回答它时,该值被正确设置为true。
checkReCaptcha(response){
console.log(this.userForm.valid);
this.captcha = response;
this.captchaControl.updateValue(true);
console.log(this.userForm.valid);
}
第一个控制台日志显示为假,第二个打印为真。
在提交按钮中,我放了禁用功能:
<button type="submit" [disabled]="!userForm.valid" class="btn btn-d">Register</button>
但按钮保持禁用状态。
如何触发按钮再次检查userForm的有效性?
更新 这是我的问题的一个例子。 http://plnkr.co/edit/Rwy6Oc5JEEm7yIJYnxJX?p=preview
当您完成表单时,即使表单有效,红色按钮也会保持禁用状态。如果您触摸任何其他输入表单(或其他提交按钮),则禁用按钮会更新并变为可用,但我希望它在定义所有输入后变为可用...
【问题讨论】:
标签: forms validation button angular recaptcha