首页 > 解决方案 > Angular Reactive Forms => 如何在不将表单标记为无效的情况下触发验证器(警告但不是阻止程序)

问题描述

我要求管理员用户可以决定验证是仅作为警告还是作为阻止程序。我仍然要求表单是完整的(即每个控件都需要 Validators.required),但模式验证器不应该总是使表单无效。无论是警告还是阻止程序,我都希望显示错误消息。

有没有办法用反应形式做到这一点?或者我应该只挂上 onChanges 并在反应形式之外验证自己,如果只是警告?

let isOnlyWarning = true //if only warning still validate and show error but keep form valid if first validator is met (i.e. has a value)

this.form.addControl(this.textFormControlName, new FormControl("", [Validators.required, Validators.pattern(this.noteSubModuleForm.RegexValidationPattern)]));

标签: angularangular-reactive-forms

解决方案


推荐阅读