ng-bootstrap-form-validation
ng-bootstrap-form-validation copied to clipboard
Custom error on form control with custom validator (AbstractControl, ValidatorFn)
I have a custom validator (cpfCnpjValidator) passed to the form control like so:
this.form = this.formBuilder.group({
document: ["", [Validators.required, cpfCnpjValidator()]]
});
How should it be referenced in the ErrorMessage array?
customErrorMessages: ErrorMessage[] = [
{
error: "pattern",
format: (label, error) => `${label.toUpperCase()} inválido.`,
},
];
- error key expects a string, passing it an empty string ("") doesn't work as well.
template:
<div class="form-group" [customErrorMessages]="customErrorMessages">
<label for="cpfCnpjInput">CPF / CNPJ</label>
<input
type="text"
class="form-control"
id="cpfCnpjInput"
autocomplete="off"
mask="000.000.000-00||00.000.000/0000-00"
formControlName="document"
/>
</div>