Module: validation-utils

CORE PACK

Oracle® JavaScript Extension Toolkit (JET)
21.0.0

G39657-01

QuickNav

JET Modules

See JET Module Loading for an overview of module usage within JET.

Description

A collection of utility functions for checking and focusing groups of validation-aware Core Pack form components. Import named functions from oj-c/validation-utils, for example import { checkValid, showMessagesAndFocusFirstInvalid } from 'oj-c/validation-utils';. Wrap the Core Pack form components whose validation state should be tracked in a group container, and give that container an id and the data-oj-context marker attribute.

Functions

checkValid(id) : {Promise}

Checks the current validity of validation-aware descendants in a container. A validation-aware descendant is a Core Pack custom element with a defined `valid` property. Wrap the components whose validation state should be tracked in a group container:

<div id="validationGroup" data-oj-context>
  <oj-c-input-text required label-hint="Name"></oj-c-input-text>
</div>

The method waits for the container BusyContext so component initialization and validation can settle before child validity is checked. Because asynchronous validation is settled before child validity is checked, the returned state is either `valid`, `invalidHidden`, or `invalidShown`. `pending` is not returned. Only descendants that are not disabled or readonly participate in validity consolidation. When a validation-aware descendant is found, its children are not searched. If no usable container is found for the id, the method logs a warning and resolves to `invalidHidden` so submit flows fail closed. The container must have the `data-oj-context` marker attribute so the utility can wait on the container's scoped BusyContext.
Parameters:
Name Type Description
id string The id of the group container.
Returns:

A promise resolving to the settled validity state found in the group: `valid`, `invalidHidden`, or `invalidShown`.

Type
Promise

focusFirstEditable(id) : {Promise}

Focuses the first editable validation-aware descendant in a container. The method waits for the container BusyContext before looking for editable validation-aware descendants, which are Core Pack custom elements with a defined `valid` property. If no usable container is found for the id, the method logs a warning and resolves without taking action. The container must have the specified id and the `data-oj-context` marker attribute so the utility can wait on the container's scoped BusyContext.
Parameters:
Name Type Description
id string The id of the group container.
Returns:

A promise resolving after focus handling is complete.

Type
Promise

showMessagesAndFocusFirstInvalid(id) : {Promise}

Shows deferred messages and focuses the first invalid component showing messages. The method waits for the container BusyContext before finding validation-aware descendants, which are Core Pack custom elements with a defined `valid` property. It calls `showMessages()` on validation-aware descendants that are not disabled or readonly, waits for any `valid` property updates to complete, then focuses the first `invalidShown` descendant in DOM order. If no usable container is found for the id, the method logs a warning and resolves without taking action. The container must have the specified id and the `data-oj-context` marker attribute so the utility can wait on the container's scoped BusyContext.
Parameters:
Name Type Description
id string The id of the group container.
Returns:

A promise resolving after messages are shown and focus handling is complete.

Type
Promise