I am trying to set error msg to branchId Input text field which is not working on first click. Next time when I click submit it shows the error massage
My form
ngOnInit() {
this.form = this.fb.group({
BRANCH_ID: ['',
[ Validators.required,
.....
],
]
this.form.controls.branchId.valueChanges
.subscribe(uploadBranchId => {
if (uploadBranchId === '1234') {
this.form.controls.branchId.setErrors({'salesBranch': true})
}
});
}
my error store library
branchId: {
....
salesBranch: 'Please provide valid branchId',
},
Form Submit event
onSubmit(){
combineWithStream.call(
this,
masterErrorProgramme({
fieldMap: this.fieldMap,
controls: this.form.controls,
errorStore: this.errorStore,
scrollToError: true,
formId: ''
}).fieldMap
);
if (this.form.valid) {
this.branchId = this.form.controls.branchId.value;
// check branchId in Database
this.serviceName.pipe(first()).subscribe((res) => {
// If branchId is not found in Database
if (res == "ID_NOT_FOUND") {
this.form.controls.branchId.setErrors({'salesBranch': true})
} else{
this._router.navigate(somePath)
}
})
}
}
the first subscribe even works perfectly fine want same thing happens in onSubmit(). this.form.controls.branchId.setErrors({'salesBranch': true})
in formmControls it is setting
errors:
salesBranch: true
__proto__: Object
but not updating in UI/browser. Please help.