I am trying to validate an input that check if the article that i am registering exists or not... so... i have a method that check in my database, then i set in a variable a boolean value.
Then i pass this variable to the validator... but something is not working.
VALIDATION FUNCTION:
validateRef(controlref: boolean): ValidatorFn {
return () => {
if ( controlref == true ) {
return { 'validref': true };
}
if (controlref == false) {
return { 'validref': false}
}
};
MY FORM:
constructor( private fb: FormBuilder ) {
this.createForm();
}
createForm() {
this.dataForm = this.fb.group({
ref: ['', [Validators.required, this.validateRef(this.controlref)]],
})
}
}
The variable that i am passing to the function, i've checked and is working... but the this.data.controls.ref.errors is always null.
HERE STACKBLITZ
can you guys guide me with this? thank you