ciao!
avrei la necessità di rendere obbligatori un campo tra email e telefono.
ho capito devo creare un custom validator, ma non riesco ad implementarlo.
questa l'ultima prova che ho fatto:
codice:
creaForm(): void {
this.frmCliente = new FormGroup({
cl_email: new FormControl('', [this.requiredAlmostOne]),
cl_telefono: new FormControl('', [this.requiredAlmostOne]),
});
}
requiredAlmostOne = (c: AbstractControl): ValidationErrors => {
const frmCliente = c.root;
if (!frmCliente) {
return null;
}
const email = frmCliente.get('cl_email')?.value ?? null;
const tel = frmCliente.get('cl_telefono')?.value ?? null;
// if (_.isEmpty(email) && _.isEmpty(tel)) {
// return {required: true};
// }
if (_.isEmpty(email) || _.isEmpty(tel)) {
return {required: true};
}
}
qualche suggerimento??