RangeValidator

RangeValidator

Validates a value against a minimum and maximum value

RangeValidator is used by DataValidatorListener for validating data objects.

An attribute of a data model may define min and max values in validation properties:


 {
    "name": "price",
    "title": "Price",
    "description": "The price of the product.",
    "type": "Number",
    "validation": {
        "minValue":5,
        "maxValue":100
    }
}
 

An operation tries to save a data object:


 var obj = {
                "price":102.5
                "model": "FS2USB42",
                "name": "USB 3.0 Adapter"
            };
 context.model("Product").save(obj).then(function() {
               return done();
           }).catch(function(err) {
               return done(err);
           });
 

and the result is:


 {
    "code": "ERANGE",
    "model": "Product",
    "field": "price",
    "message": "The value should be between 5 to 100."
}
 

Constructor

new RangeValidator(min, max)

Parameters:
Name Type Description
min number | Date | * A value which represents the minimum value
max number | Date | * A value which represents the maximum value
Properties:
Name Type Description
minValue * Gets or sets a value which represents the minimum value
maxValue * Gets or sets a value which represents the maximum value
message string Gets or sets a string which represents a custom validator message.
Source:

Extends

Methods

getContext() → {DataContext|*}

Gets the current data context, if any.
Inherited From:
Source:
Returns:
Type
DataContext | *

setContext(context)

Sets the current data context.
Parameters:
Name Type Description
context DataContext | *
Inherited From:
Source:

validateSync(val) → {Object|undefined|*}

Validates the given value. If validation fails, the operation will return a validation result.
Parameters:
Name Type Description
val *
Source:
Returns:
Type
Object | undefined | *