lib/middleware/content/validate.js
function performValidation(field) {
        return function(rule, cb) {
            var valueToBeValidated = kontx.args.fields[field._id],
                validate = validator.get(rule);

            //Undefined values do not need to be validated unless the field is required
            if (rule.type === 'required' || !_.isUndefined(valueToBeValidated)) {
                if (_.isArray(valueToBeValidated)) {
                    q.all(
                        _.map(valueToBeValidated, function(value) {
                            return validate(value, rule.options);
                        })
                    )
                        .then(
                            function() {
                                cb();
                            },
                            function() {
                                cb(createError(400, validationTemplate({
                                    label: field.label
                                })));
                            }
                    );
                } else {
                    validate(valueToBeValidated, rule.options)
                        .then(
                            function() {
                                cb();
                            },
                            function() {
                                cb(createError(400, validationTemplate({
                                    label: field.label
                                })));
                            }
                    );
                }
            } else {
                cb();
            }
        };
    }
function performValidation(field) {
        return function(rule, cb) {
            var valueToBeValidated = kontx.args.fields[field._id],
                validate = validator.get(rule);

            //Undefined values do not need to be validated unless the field is required
            if (rule.type === 'required' || !_.isUndefined(valueToBeValidated)) {
                if (_.isArray(valueToBeValidated)) {
                    q.all(
                        _.map(valueToBeValidated, function(value) {
                            return validate(value, rule.options);
                        })
                    )
                        .then(
                            function() {
                                cb();
                            },
                            function() {
                                cb(createError(400, validationTemplate({
                                    label: field.label
                                })));
                            }
                    );
                } else {
                    validate(valueToBeValidated, rule.options)
                        .then(
                            function() {
                                cb();
                            },
                            function() {
                                cb(createError(400, validationTemplate({
                                    label: field.label
                                })));
                            }
                    );
                }
            } else {
                cb();
            }
        };
    }
function performValidation ( field ) { return function ( rule , cb ) { var valueToBeValidated = kontx . args . fields [ field . _id ] , validate = validator . get ( rule ) ; //Undefined values do not need to be validated unless the field is required if ( rule . type === 'required' || ! _ . isUndefined ( valueToBeValidated ) ) { if ( _ . isArray ( valueToBeValidated ) ) { q . all ( _ . map ( valueToBeValidated , function ( value ) { return validate ( value , rule . options ) ; } ) ) . then ( function ( ) { cb ( ) ; } , function ( ) { cb ( createError ( 400 , validationTemplate ( { label : field . label } ) ) ) ; } ) ; } else { validate ( valueToBeValidated , rule . options ) . then ( function ( ) { cb ( ) ; } , function ( ) { cb ( createError ( 400 , validationTemplate ( { label : field . label } ) ) ) ; } ) ; } } else { cb ( ) ; } } ; }
Function actually tests the field for a specific validation rule.
Function actually tests the field for a specific validation rule .