I'm trying to create a simple custom validator. basically if one variable (behalf) is true, the field must be mandatory. That's all.
I don't know why, but I cannot read the variable behalf. It's throw undefined. Any clue about how to handle this ?
behalf = false;
private validateName(){
if (this.behalf && this.nameB.text != '') {
return {
invalidName : true
};
}
else{
return null;
}
}
constructor (private builder: FormBuilder){
this.title = new Control('', Validators.required);
this.name = new Control('', this.validateName);
this.type = new Control('', Validators.required);
this.desc = new Control('');
this.hideTitle = new Control('');
this.end = new Control('', Validators.required);
this.formBook = builder.group({
title: this.title,
name: this.name,
type: this.type,
desc: this.desc,
hideTitle: this.hideTitle,
end: this.end
});
}