Final Class: RequiredValidator

Oracle® JavaScript Extension Toolkit (JET)
17.1.0

G12196-01

Since:
  • 0.6.0
Module:
  • ojvalidator-required

QuickNav

Description

Constructs a RequiredValidator that ensures that the value provided is not empty.


Usage

Signature:

final class RequiredValidator implements Validator<object|string|number>

Typescript Import Format
//This class is exported directly as module. To import it
import RequiredValidator= require("ojs/ojvalidator-required");

For additional information visit:


Final classes in JET

Classes in JET are generally final and do not support subclassing. At the moment, final is not enforced. However, this will likely change in an upcoming JET release.


See:
  • oj.AsyncRequiredValidator

Constructor

new RequiredValidator(options)

Constructs a RequiredValidator that ensures that the value provided is not empty.
Parameters:
Name Type Argument Description
options oj.RequiredValidator.ValidatorOptions <optional>
an object literal used to provide an optional hint and error message.

See:
  • oj.AsyncRequiredValidator

Methods

getHint : {string|null}

A message to be used as hint, when giving a hint on the expected pattern. There is no default hint for this property.
Returns:

a hint message or null if no hint is available in the options

Type
string | null

validate(value) : {void}

Validates value to be non-empty
Parameters:
Name Type Description
value any value that is being validated
Throws:
when fails required-ness check
Type
Error
Returns:
Type
void

Type Definitions

ValidatorOptions

Properties:
Name Type Argument Description
hint string <optional>
an optional hint text. There is no default hint provided by this validator.
label string <optional>
an optional label text used when the {label} token is passed into messageSummary or messageDetail.
messageDetail ?(string | (({label: string}) => string)) <optional>
an optional custom error message used for creating the detail part of the message, when the value provided is empty. When not present, the default message detail is the resource defined with the key oj-validator.required.detail.

If messageDetail is a string, the messageDetail string is passed as the 'pattern' parameter to oj.Translations.html#applyParameters. As stated in that documentation, if you are using a reserved character, you need to escape it with a dollar character ('$').

Tokens: {label} - this token can be used to substitute the label of the component at runtime.

Example:
"A value is required for the field '{label}'."

If messageDetail is a function, the messageDetail function is called with the {label} parameter.

Example:
messageDetail: (p: {label}) => `A value is required for the field '${p.label}'.`

messageSummary string <optional>
an optional custom error message summarizing the error. When not present, the default message summary is the resource defined with the key oj-validator.required.summary.

The messageSummary string is passed as the 'pattern' parameter to oj.Translations.html#applyParameters. As stated in that documentation, if you are using a reserved character, you need to escape it with a dollar character ('$').

Tokens: {label} - this token can be used to substitute the label of the component at runtime.

Example:
"'{label}' Required"