formcycle 8.3.6 - JavaScript for forms
    Preparing search index...

    Interface XmValidator

    The main interface for interacting with the form validator. You can use it, for example, to listen to certain events during form validation.

    interface XmValidator {
        _getVal(item: JQuery, type: string): unknown;
        findAllPotentialReferences(
            elements: string | HTMLElement | JQuery<HTMLElement> | HTMLElement[],
            opts?: XmValidatorFindReferencesOptions,
        ): JQuery;
        off<K extends keyof XmValidatorCallbacks>(
            event: K,
            eventCallback: XmValidatorCallbacks[K],
        ): void;
        on<K extends keyof XmValidatorCallbacks>(
            event: K,
            eventCallback: XmValidatorCallbacks[K],
        ): void;
        setAnimateScrollToError(animate: boolean): void;
        updateValidationState(base: JQuery, forceUpdate?: boolean): void;
    }
    Index

    Methods

    • Finds the value of the given form element, irrespective of its type. The returned value depends on the form element's type.

      Parameters

      • item: JQuery

        Form element to process.

      • type: string

        The value of the given form element, usually its tag name or the type property of the input element.

      Returns unknown

      This is an internal method.

    • Finds all (potential) references of the given elements. The given elements themselves are not included in the returned result.

      References are for example elements that have a hidden-if, read-only-if or required-if condition on one of the given elements.

      Parameters

      • elements: string | HTMLElement | JQuery<HTMLElement> | HTMLElement[]

        Elements for which to find references.

      • Optionalopts: XmValidatorFindReferencesOptions

        Options for which elements to find. By default, finds all known references.

      Returns JQuery

      All references that were found.

    • Register a callback function for one of the events issued during form validation.

      Uncaught errors in callbacks are caught, logged, and ignored otherwise.

      The following events are available:

      • requestBegin: When form validation was requested, before element state updates such as hidden-if conditions.
      • begin: When form validation starts, after element state updates such as hidden-if conditions.
      • progress: When progress is made during form validation, i.e. every time a single form field was validated. Form validation consists of validation a set of form elements, possibly the entire form.
      • finish: When form validation finishes.
      • requestFinish: When form validation request was finished.
      // Log a console message when the event is triggered
      xm_validator.on("requestBegin", data => console.log("validate-request", data));
      xm_validator.on("begin", data => console.log("validate-start", data));
      xm_validator.on("progress", data => console.log("progress", data));
      xm_validator.on("finish", data => console.log("validate-finish", data));
      xm_validator.on("requestFinish", data => console.log("validate-finish", data));

      Type Parameters

      Parameters

      • event: K

        Name of the event to listen to.

      • eventCallback: XmValidatorCallbacks[K]

        Listener that is invoked when the event occurs.

      Returns void

    • When the form is submitted and a form field is not valid, the browser window is scrolled so that the invalid field becomes visible. By default, this scrolling is animated. This method can be used to disable the animation so that the scrolling is instantaneous.

      Parameters

      • animate: boolean

        Whether to animate the scrolling.

      Returns void

    • Updates the validation state (conditions such as hidden-if or read-only-if) for all given elements.

      Parameters

      • base: JQuery

        Base with elements to update.

      • OptionalforceUpdate: boolean

        When true, elements are updated if when their state does not have changes (e.g. an element is hidden even if already hidden).

      Returns void