LuCI.validation. Validator

new Validator(field, type, optional, function, validatorFactory) → {Validator}

Parameters:
NameTypeDescription
fieldstring

the UI field to validate.

typestring

type of validator.

optionalboolean

set the validation result as optional.

functionvfunc

validation function.

validatorFactoryValidatorFactory

a ValidatorFactory instance.

Returns:

a Validator instance.

Type: 
Validator

Methods

apply(name, value, args) → {*}

Apply a validation function by name or directly via function reference. If a name is provided it resolves it via the factory's registered types.

Parameters:
NameTypeDescription
namestring | function

Validator name or function.

value*

Value to validate (optional; defaults to field value).

argsArray

Arguments passed to the validator function.

Returns:

Validator result.

Type: 
*

assert(condition, message) → {boolean}

Assert a condition and update field error state.

Parameters:
NameTypeDescription
conditionboolean

Condition that must be true.

messagestring

Error message when assertion fails.

Returns:

True when assertion is true, false otherwise.

Type: 
boolean

validate() → {boolean}

Validate the associated field value using the compiled validator stack and any additional validators provided at construction time. Emits 'validation-failure' or 'validation-success' CustomEvents on the field.

Returns:

True if validation succeeds, false otherwise.

Type: 
boolean