RequiredValidator

most-data/data-validator~ RequiredValidator

Validates a required attribute

RequiredValidator is used by DataValidatorListener for validating data objects.

An attribute of a data model may be defined as required:


     {
        "name": "price",
        "title": "Price",
        "description": "The price of the product.",
        "type": "Number",
        "nullable": false
    }
     

An operation tries to save a data object without price:


     var obj = {
                "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": "EREQUIRED",
        "model": "Product",
        "field": "price",
        "message": "A value is required."
    }
     

Constructor

new RequiredValidator()

Source:

Extends

  • most-data/data-validator~DataValidator

Methods

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 | *