File

libs/core/validation-errors/src/internal-validator-messages.ts

Index

Properties

Properties

errorMessage
Type string
ignoreValidators (Optional)
Type string[]
validatorId
Type string
validatorName
Type string
import { LocalizeFn } from '@angular/localize/init';

declare let $localize: LocalizeFn;

export interface InternalValidatorMessage {
  validatorId: string;
  validatorName: string;
  errorMessage: string;
  // Hide following validation messages when the custom validator presents.
  // Eg. When `nxDatefieldParse` message is available, do not show `required` message for the field
  ignoreValidators?: string[];
}

/**
 * Create an enum variable in order to identify the different 'nxDatefieldParse' errors with a unique
 * identifier.
 */
export enum ValidatorId {
  nxDatefieldParse = 'nxDatefieldParse',
  nxDatefieldParseYears = 'nxDatefieldParse.year'
}

/**
 * NDBX datefield adds a validation error `nxDatefieldParse` when it cannot parse the given input.
 * We need a way to show such errors those are added to the `form-control` by third party libraries.
 * When such errors are shown, we need an option to ignore other validator errors as well.
 *
 * Eg. when `nxDatefieldParse` error is shown, hide `required` error.
 *
 * We can use `INTERNAL_VALIDATOR_MESSAGES` to configure such errors.
 *
 * @param validatorName name of the validator
 * @param errorMessage localized error message to be shown to the user
 * @param ignoreValidators array of validator names to be ignored when this validator is shown
 */
export const INTERNAL_VALIDATOR_MESSAGES: InternalValidatorMessage[] = [
  {
    validatorId: ValidatorId.nxDatefieldParse,
    validatorName: 'nxDatefieldParse',
    errorMessage: $localize`:@@validation.error.nxDatefieldParse:This field has an invalid format!`,
    ignoreValidators: ['required']
  },
  {
    validatorId: ValidatorId.nxDatefieldParseYears,
    validatorName: 'nxDatefieldParse',
    errorMessage: $localize`:@@validation.error.nxDatefieldParse.years:Please use the format YYYY using only numbers.`,
    ignoreValidators: ['required']
  }
];

results matching ""

    No results matching ""