About Oracle JET Validators and Converters

The Oracle JET framework provides converter classes that convert user input strings into the data type expected by the application and validator classes that enforce a validation rule on those input strings.

For example, you can use Oracle JET's oj.IntlDateTimeConverter to convert a user-entered date to a Date object for use by the application's ViewModel and then use oj.DateTimeRangeValidator to validate that input against a specified time range. You can also use converters to convert Date or Number objects to a string suitable for display or convert color object formats.

To retrieve the converter or validator factory for a registered type, Oracle JET provides the oj.Validation class which includes methods to register and retrieve converter and validator factories.

If the converters or validators included in the Oracle JET framework are not sufficient for your application, you can create custom converters or validators. Optionally, you can provide a custom factory that implements the contract for a converter using oj.ConverterFactory or a validator using oj.ValidatorFactory and register the converter or validator with the oj.Validation class. The oj.Validation class enables you to access your custom converter or validator using the same mechanisms as you would use with the Oracle JET standard converters and validators.

Topics:

About Validators

All Oracle JET editable components support a value option and provide UI elements that allow the user to enter or choose a value. These components also support other options that page authors can set that instruct the component how it should validate its value.

An editable component may implicitly create a built-in converter and/or built-in validators for its normal functioning when certain options are set.

For example, editable components that support a required option create the required validator implicitly when the option is set to true. Other components like ojInputDate, ojInputDateTime, and ojInputTime create a datetime converter to implement its basic functionality.

Topics

Oracle JET Validators

The following table describes the Oracle JET validators and provides links to the API documentation:

Validator Description Link to API

oj.DateTimeRangeValidator

Validates that the input date is between two dates, between two times, or within two date and time ranges

oj.DateTimeRangeValidator

oj.DateRestrictionValidator

Validates that the input date is not a restricted date

oj.DateRestrictionValidator

oj.LengthValidator

Validates that an input string is within a specified length

oj.LengthValidator

oj.NumberRangeValidator

Validates that an input number is within a specified range

oj.NumberRangeValidator

oj.RegExpValidator

Validates that the regular expression matches a specified pattern

oj.RegExpValidator

oj.RequiredValidator

Validates that a required entry exists

oj.RequiredValidator

Oracle JET Component Validation Options

The options that a component supports is part of its API, and the following validation specific options apply to most editable components.

Component Option HTML5 Attribute Description

converter

 

When specified, the converter instance is used over any internal converter the component might create. On components such as ojInputText, you may need to specify this option if the value must be processed to and from a number or a date value.

countBy

 

When specified on oj.LengthValidator, the countBy option enables you to change the validator’s default counting behavior. By default, this option is set to codeUnit, which uses JavaScript's String length property to count a UTF-16 surrogate pair as length === 2. Set this to codePoint to count surrogate pairs as length ===1.

max

max

When specified on the HTML element or as an option on an Oracle JET component like ojInputDate or ojInputNumber, the component creates an implicit range validator.

min

min

When specified on the HTML element or as an option of an Oracle JET component like ojInputDate or ojInputNumber, the component creates an implicit range validator.

pattern

pattern

When specified on the HTML element or as an option on an Oracle JET component like ojInputText, ojInputPassword, or ojTextarea, the component creates an implicit regExp validator using the pattern specified.

placeholder

placeholder

When specified on the HTML element or as an option on an Oracle JET component, it displays a placeholder in most components.

required

required

When specified on the HTML element or as an option on an Oracle JET component, the component creates an implicit required validator.

validators

 

When specified, the component uses these validators along with the implicit validators to validate the UI value.

Some editable components do not support specific validation options as they might be irrelevant to its intrinsic functioning. For example, ojRadioset and ojCheckboxset do not support a converter option since there is nothing for the converter to convert. For an exact list of options and how to use them, refer to the Options section in the component's API documentation. For Oracle JET API documentation, see JavaScript API Reference for Oracle® JavaScript Extension Toolkit (JET). Select the component you're interested in viewing from the API list.

Note:

When the element that the Oracle JET component is initialized from also has HTML5 validation attributes, then these often drive the initial value of the corresponding option on the component if the option is not already present.

Oracle JET Component Validation Methods

Oracle JET editable components support the following methods for validation purposes. For details on how to call this method, its parameters and return values, refer to the component’s API documentation for details.

Component Method Description

isValid()

Use this method to detect the current validity state of a component. The method returns the boolean true if it's valid and false if it's invalid.

refresh()

Use this method when the DOM the component relies on changes, such as the label associated to the input component.

reset()

Use this method to reset the component's display value to reflect its stored option value.

validate()

Use this method to validate the component using the current display value.

For details on calling a component’s method, parameters, and return values, See the Methods section of the component's API documentation in JavaScript API Reference for Oracle® JavaScript Extension Toolkit (JET). You can also find detail on how to register a callback for or bind to the event and for information about what triggers the events. Select the component you're interested in viewing from the API list.

About Converters

The Oracle JET converters include date-time, number, and color converters and are described in the following table.

Converter Description Link to API

oj.ColorConverter

Converts oj.Color object formats

oj.ColorConverter

oj.IntlDateTimeConverter

Converts a string to a Date or a Date to a string

oj.IntlDateTimeConverter

oj.IntlNumberConverter

Converts a string to a number or formats a number or Number object value to a string

oj.IntlNumberConverter