Skip to content
This repository was archived by the owner on Jan 5, 2022. It is now read-only.
This repository was archived by the owner on Jan 5, 2022. It is now read-only.

Custom error on form control with custom validator (AbstractControl, ValidatorFn) #97

@ruslanpascoal2

Description

@ruslanpascoal2

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions