Initializing help system before first use

EntityValidator

Register and call validation functions on entities.

Method summary

name description
checkValue Check a value is valid for a given entity.
getValidator Get the validation function attached to an entity for a given dimension.
isBoolean Check if value is a boolean. Allows null and undefined as they are used to clear array elements.
isInteger Check if value is an integer. Allows null and undefined as they are used to clear array elements.
isReal Check if value is a real. Allows null and undefined as they are used to clear array elements.
removeValidator Remove the validation function attached to an entity for a given dimension.
setValidator Set a validation function on a model entity for a given dimension.

Methods

method
static checkValue ( entity, value, dimension, key ) → {Result}

Check a value is valid for a given entity and optionally a specific dimension. Base (primitive) type checking is performed if in the NORMAL_DATA dimension then custom validation is performed.

Parameters:
params
Name Type Argument Default Description
entity
type
string | ModelEntity
name or instance of the entity to validate against
value
type
*
The value to check
dimension
type
insight.enums.EntityDataDimension
optional  insight.enums.EntityDataDimension.NORMAL_DATA The data dimension to check data in
key
type
Array.<*>
optional  Array element key, if applicable
details
Returns:
returns table
Type Description
type
Result
Validation result and message, if in error
Example
examples
var result = insight.validation.EntityValidator.checkValue('INTEGER_ENTITY', 120);
Back to Top
method
static getValidator ( entity, dimension ) → {function|undefined}

Get the validation function attached to an entity for a given dimension.

Parameters:
params
Name Type Argument Default Description
entity
type
string | ModelEntity
name or instance of the entity
dimension
type
insight.enums.EntityDataDimension
optional  insight.enums.EntityDataDimension.NORMAL_DATA The data dimension
details
Returns:
returns table
Type Description
type
function | undefined
The validator callback or undefined if not set
Example
examples
insight.validation.EntityValidator.getValidator('MY_ENTITY')
Back to Top
method
static isBoolean ( value ) → {boolean}

Check if value is a boolean. Allows null and undefined as they are used to clear array elements.

Parameters:
params
Name Type Description
value
details
Returns:
returns table
Type Description
type
boolean
Example
examples
insight.validation.EntityValidator.isBoolean(false); // returns true
Back to Top
method
static isInteger ( value ) → {boolean}

Check if value is an integer. Allows null and undefined as they are used to clear array elements.

Parameters:
params
Name Type Description
value
details
Returns:
returns table
Type Description
type
boolean
Example
examples
insight.validation.EntityValidator.isInteger(0.45); // returns false
Back to Top
method
static isReal ( value ) → {boolean}

Check if value is a real. Allows null and undefined as they are used to clear array elements.

Parameters:
params
Name Type Description
value
details
Returns:
returns table
Type Description
type
boolean
Example
examples
insight.validation.EntityValidator.isReal(0.45); // returns true
Back to Top
method
static removeValidator ( entity, dimension ) → {boolean}

Remove the validation function attached to an entity for a given dimension.

Parameters:
params
Name Type Argument Default Description
entity
type
string | ModelEntity
name or instance of the entity
dimension
type
insight.enums.EntityDataDimension
optional  insight.enums.EntityDataDimension.NORMAL_DATA The data dimension
details
Returns:
returns table
Type Description
type
boolean
Whether the validator was removed or not
Example
examples
insight.validation.EntityValidator.removeValidator('MY_ENTITY');
insight.validation.EntityValidator.getValidator('MY_ENTITY'); // returns null
Back to Top
method
static setValidator ( entity, validator, dimension ) → {boolean}

Set a validation function on a model entity for a given dimension. This will overwrite any existing validation on the entity except for basic type checking validation that is always applied.

Parameters:
params
Name Type Argument Default Description
entity
type
string | ModelEntity
name or instance of the entity to attach the validator
validator
type
EntityValidatorCallback
The validation function
dimension
type
insight.enums.EntityDataDimension
optional  insight.enums.EntityDataDimension.NORMAL_DATA The data dimension to attach the validator to
details
Returns:
returns table
Type Description
type
boolean
Whether the validation function was stored
Example
examples
insight.validation.EntityValidator.setValidator('MY_ENTITY', function (entityName, value, indices) {
     var result = new insight.validation.Result(false);
     result.errorMessage = 'Invalid value ' + value;
     return result;
});
Back to Top