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

Hierarchy

  • XmValidator

Index

Methods

_getVal

  • _getVal(item: JQuery, type: string): unknown
  • Finds the value of the given form element, irrespective of its type. The returned value depends on the form element's type.

    deprecated

    This is an internal method.

    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

findAllPotentialReferences

  • 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 | HTMLElement[] | JQuery

      Elements for which to find references.

    • Optional opts: XmValidatorFindReferencesOptions

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

    Returns JQuery

    All references that were found.

off

  • off<K>(event: K, eventCallback: XmValidatorCallbacks[K]): void
  • Removes an event callback previously added via on.

    Type parameters

    • K: keyof XmValidatorCallbacks

      Type of the event name for which to remove a listener.

    Parameters

    • event: K

      Name of the event to for which to remove a listener.

    • eventCallback: XmValidatorCallbacks[K]

      Listener to remove.

    Returns void

on

  • on<K>(event: K, eventCallback: XmValidatorCallbacks[K]): void
  • 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

    • K: keyof XmValidatorCallbacks

      Type of the event name for which to register a listener.

    Parameters

    • event: K

      Name of the event to listen to.

    • eventCallback: XmValidatorCallbacks[K]

      Listener that is invoked when the event occurs.

    Returns void

setAnimateScrollToError

  • setAnimateScrollToError(animate: boolean): 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

updateValidationState

  • updateValidationState(base: JQuery, forceUpdate?: boolean): 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.

    • Optional forceUpdate: 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