我有一个包含2个字段的表单
1)最小值
2)最大值
以下是我的表格:
<ivanapp.SimpleValueViewer
android:id="@+id/price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:label="Цена"/>
这是我的最小最大验证器:
constructor(public cdr:ChangeDetectorRef) {
this.feedbackForm = new FormGroup({
minScore: new FormControl('', [Validators.pattern(/^[0-9]+$/),Validators.required,Validators.minLength(1),Validators.maxLength(1)]),
maxScore: new FormControl('', [Validators.pattern(/^[0-9]+$/),Validators.required,Validators.minLength(1),Validators.maxLength(1)])
});
this.feedbackForm.setValidators(this.minMaxValidator());
}
如果在此处输入包含文本的最大值为“ 12t”,则由于else块,表格未显示任何错误 min.setErrors(null); max.setErrors(null);
由于在else中输入了错误(这会导致错误为null),所以表单控制中的模式被绕过。我想立即应用所有验证器(pattern和min max)。