EntityValidator
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
- 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:
paramsName Type Argument Default Description entity typestring | ModelEntityname or instance of the entity to validate against value type*The value to check dimension typeinsight.enums.EntityDataDimensionoptional insight.enums.EntityDataDimension.NORMAL_DATA The data dimension to check data in key typeArray.<*>optional Array element key, if applicable detailsReturns:returns tableType Description typeResultValidation result and message, if in error Example
examples
Back to Topvar result = insight.validation.EntityValidator.checkValue('INTEGER_ENTITY', 120);
- static getValidator ( entity, dimension ) → {function|undefined}
-
Get the validation function attached to an entity for a given dimension.
Parameters:
paramsName Type Argument Default Description entity typestring | ModelEntityname or instance of the entity dimension typeinsight.enums.EntityDataDimensionoptional insight.enums.EntityDataDimension.NORMAL_DATA The data dimension detailsReturns:returns tableType Description typefunction | undefinedThe validator callback or undefined if not set Example
examples
Back to Topinsight.validation.EntityValidator.getValidator('MY_ENTITY')
- static isBoolean ( value ) → {boolean}
-
Check if value is a boolean. Allows null and undefined as they are used to clear array elements.
Parameters:
paramsName Type Description value detailsReturns:returns tableType Description typebooleanExample
examples
Back to Topinsight.validation.EntityValidator.isBoolean(false); // returns true
- static isInteger ( value ) → {boolean}
-
Check if value is an integer. Allows null and undefined as they are used to clear array elements.
Parameters:
paramsName Type Description value detailsReturns:returns tableType Description typebooleanExample
examples
Back to Topinsight.validation.EntityValidator.isInteger(0.45); // returns false
- static isReal ( value ) → {boolean}
-
Check if value is a real. Allows null and undefined as they are used to clear array elements.
Parameters:
paramsName Type Description value detailsReturns:returns tableType Description typebooleanExample
examples
Back to Topinsight.validation.EntityValidator.isReal(0.45); // returns true
- static removeValidator ( entity, dimension ) → {boolean}
-
Remove the validation function attached to an entity for a given dimension.
Parameters:
paramsName Type Argument Default Description entity typestring | ModelEntityname or instance of the entity dimension typeinsight.enums.EntityDataDimensionoptional insight.enums.EntityDataDimension.NORMAL_DATA The data dimension detailsReturns:returns tableType Description typebooleanWhether the validator was removed or not Example
examples
Back to Topinsight.validation.EntityValidator.removeValidator('MY_ENTITY'); insight.validation.EntityValidator.getValidator('MY_ENTITY'); // returns null
- 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:
paramsName Type Argument Default Description entity typestring | ModelEntityname or instance of the entity to attach the validator validator typeEntityValidatorCallbackThe validation function dimension typeinsight.enums.EntityDataDimensionoptional insight.enums.EntityDataDimension.NORMAL_DATA The data dimension to attach the validator to detailsReturns:returns tableType Description typebooleanWhether the validation function was stored Example
examples
Back to Topinsight.validation.EntityValidator.setValidator('MY_ENTITY', function (entityName, value, indices) { var result = new insight.validation.Result(false); result.errorMessage = 'Invalid value ' + value; return result; });