@fkui/logic
    Preparing search index...

    Interface ValidationServiceInterface

    interface ValidationServiceInterface {
        isAnyTouched: boolean;
        addValidationErrorMessages(
            validationErrorMessageMap: Record<ValidatorName | string, string>,
        ): void;
        addValidatorsToElement(
            element: ValidatableHTMLElement,
            validatorConfigs: ValidatorConfigs,
            isBaseConfigs?: boolean,
        ): void;
        clearAllStates(): void;
        clearErrorMessages(): 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;
        setErrorMessages(
            messages: Record<string, string>,
            options?: { clear?: boolean },
        ): 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>;
    }
    Index

    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.

    • Set error messages for one or more validators.

      The mapping should contain an object with the validator descriptor as key and the error message as value. A descriptor is a dot separated list of keywords:

      • One or more validator names.
      • An input type (text, radio, checkbox, select or textarea).

      When multiple validator names are given the first one is the validator yielding the error and any subsequent validators is used when the first validator is combined with these validators (no matter if those yield an error or not).

      • required - the error message when required yields an error.
      • required.date - the error message when required yields an error on an input field which also uses the date validator.
      • required.radio - the error message when required yield an error on an input field of type radiobutton.
      • required.whitelist.textarea - the error message when required yield an error on an textarea which also uses the whitelist validator.

      New translations will be merged with existing messages and overwritten if they already exists. Do note that if a more specific error message already exists the specific one will not be affected (e.g. setting the error for required whould not affect required.radio if it exists).

      Set clear to true to reset all previous messages (overwrite instead of merge).

      Parameters

      • messages: Record<string, string>

        the map with error messages for validators

      • Optionaloptions: { clear?: boolean }

      Returns void