angular - 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)]));
解决方案
推荐阅读
- c# - 排序列表
和重复的键 - reactjs - 为什么向 ag-grid-react 添加一列会导致所有单元格重新呈现?
- html - 打开角度材料对话框时,父组件应处于活动状态
- python - 无效的密码格式或未知的散列算法。在 django 休息框架中
- python - 无法将数据写入 CSV 文件
- node.js - Module.create 不从输入中获取数据,req.body 为空
- python - ValueError:操作数无法与形状一起广播 (720,1280) (720,1281)
- mysql - 这三个查询之间是否有任何性能差异
- java - Intellij 搜索某些类不工作,但到处搜索工作
- c# - 从下拉列表中选择值后显示文本框值(应显示从下拉列表中选择产品后的产品数量)