Interface ValidationServiceInterface

interface ValidationServiceInterface {
    isAnyTouched: boolean;
    addValidationErrorMessages(
        validationErrorMessageMap: Record<string, string>,
    ): void;
    addValidatorsToElement(
        element: ValidatableHTMLElement,
        validatorConfigs: ValidatorConfigs,
        isBaseConfigs?: boolean,
    ): void;
    clearAllStates(): void;
    getValidatorByName<TConfig = ValidatorConfig>(
        name: string,
    ): Validator<TConfig>;
    isValid(
        src: null | string | string[] | Element | Element[],
        root?: Element | Document,
    ): Promise<boolean>;
    registerValidator<TConfig = ValidatorConfig>(
        validator: Validator<TConfig>,
    ): void;
    removeValidatorsFromElement(element: ValidatableHTMLElement): void;
    resetState(element: null | string | Element): void;
    setError(element: null | string | Element, message: string): void;
    setState(
        element: null | string | Element,
        validationState: ValidationState,
    ): void;
    setSubmitted(element: null | string | Element): void;
    setTouched(element: null | string | Element): void;
    validateAllElements(root: string | Element): Promise<void>;
    validateElement(
        element: null | string | Element,
    ): Promise<ValidationResult>;
}

Properties

isAnyTouched: boolean

Whether any of the fields are touched

Methods

  • Add validators to an element.

    Parameters

    • element: ValidatableHTMLElement

      the element to add validator to

    • validatorConfigs: ValidatorConfigs

      the defintion of validators to be addede.

    • OptionalisBaseConfigs: boolean

      is a boolean which indicates if this configuration should always lay as a base configuration even if overlaying code is changing its validators.

      As an example there is FEmailTextField which sets its own EmailValidator in the constructor. Then the app-code can add its own validatorsConfig on top of that (example: required: { enabled: $someValue } }). Setting isBaseConfigs to true preserves the validatorConfig set by FEmailTextField as the app code changes the required validatorConfig (which triggers addValidatorsToElement() again)

    Returns void

  • Check if given element(s) are valid.

    When passing multiple elements all of them must be valid. For non-input elements (fieldsets, divs, etc) it checks whenever all descendants are valid. Returns true if array is empty.

    Note: this function does not update the validity state (i.e. run validators) but only checks the current state! Use ValidationServiceInterface.validateElement to update state.

    Parameters

    • src: null | string | string[] | Element | Element[]

      Element instance or id.

    • Optionalroot: Element | Document

      Element (or document) to query when looking up elements by id.

    Returns Promise<boolean>

    Resolves to true if all given elements (or descendants) are valid. Empty array resolves to true.