示例#1
0
 validationPromise = validationPromise.then(function() {
   return validate.async(processor, processor.$validate).catch(function(errors) {
     validationErrors.push({
       processor: processor.name,
       package: processor.$package,
       errors: errors
     });
     log.error('Invalid property in "' + processor.name + '" (in "' + processor.$package + '" package)');
     log.error(errors);
   });
 });
 validateInput(element) {
     validate.async(this.createObjectFromInputs(this.inputs), this.constraints || {}).then(
         success => {
             this.errors = {};
             this.showAllErrors();
         },
         function(errors) {
             if (errors instanceof Error) {
                 throw errors;
             } else {
                 this.errors = errors;
                 this.showErrorsForInput(element, this.errors[element.name]);
             }
         }.bind(this)
     );
 }
    return function (req, res, next) {

            //validate async function for input validation
        validate.async(req.body, validationConstrain, {
            format: "flat"
        }).then(function () {
            next();
        }, function (errors) {
            return res.send({
                success: true,
                message: errors[0]
            });

        });

    };
 handleSubmission() {
     validate.async(this.createObjectFromInputs(this.inputs), this.constraints || {}).then(
         function() {
             this.errors = {};
             this.showAllErrors();
             this.form.submit();
         }.bind(this),
         function(errors) {
             if (errors instanceof Error) {
                 throw errors;
             } else {
                 this.errors = errors;
                 this.showAllErrors();
             }
         }.bind(this)
     );
 }
function _adicionar($scope, $ionicPopup, tarefa) {
	validate
		.async(tarefa, TAREFA_VALIDATE)
		.then(function() {
			Tarefas.insert(tarefa);
			$scope.tarefa = {};
			Util.$apply();
		}, function (validationErrors) {
			var errors = [];
			_.each(validationErrors, function (field) {
				errors = errors.concat(field);
			});
			$ionicPopup.alert({
					title: 'ToDo App!',
					template: errors.join('<br>')
				});
		});
}
示例#6
0
exports.validate = function(req, res, next, validate) {
    if (validate) {
        var constraints = {};
        var attributes = {};

        for (var i = 0; i < validate.length; i++) {
            attributes[validate[i].name] = req[validate[i].source][validate[i].name] || null;
            constraints[validate[i].name] = validate[i].rules;
        }

        valid.async(attributes, constraints)
        .then(function(result) {
            next();
        }, function(err) {
            res.send(400, {error: err });
        });
    } else {
        next();
    }
};
示例#7
0
 null,  function (validation, composer) {
     var target      = validation.object,
         nested      = {},
         constraints = _buildConstraints(target, nested);
     if (constraints) {
         var scope     = validation.scope,
             results   = validation.results,
             validator = Validator(composer); 
         if (validation.isAsync) {
             return validatejs.async(target, constraints, DETAILED)
                 .then(function (valid) {
                      return _validateNestedAsync(validator, scope, results, nested);
                 }, function (errors) {
                     if (errors instanceof Error) {
                         return Promise.reject(errors);
                     }
                     return _validateNestedAsync(validator, scope, results, nested).then(function () {
                         _mapResults(results, errors);
                     });
                 });
         } else {
             var errors = validatejs(target, constraints, DETAILED);
             for (var key in nested) {
                 var child = nested[key];
                 if (child instanceof Array) {
                     for (var i = 0; i < child.length; ++i) {
                         validator.validate(child[i], scope, results.addKey(key + '.' + i));
                     }
                 } else {
                     validator.validate(child, scope, results.addKey(key));
                 }
             }
             _mapResults(results, errors);
         }
     }
 }