_onChangeField(refField){ if(this.formClicked > 0){ const value = this.refs[refField].getValue() const isValid = validate.single(value, this.formValidate[refField]) this._triggerFieldError(isValid, refField) } }
once: function (value, options, name) { var errors = []; var opts = []; var validationOpts = []; // Check if name was passed, determines which validate method to use if (name) { // Since name exists, use the main validate method but just pass one // property to it. Need to structure the objects it expects first. opts[name] = value; validationOpts[name] = processOptions(options); // Use main validate method, gives us better handling of custom messages // and key path name prepending. errors = validatejs(opts, validationOpts); // can.Map.define expects an array of strings, but main validate method // returns an object. if (errors) { errors = errors[name]; } } else { errors = validatejs.single(value, processOptions(options)); } return errors; },
comment: function (review) { var commentText = $('[data-id="'+review.id+'"] #comment-input').val().trim(); if(undefined !== validate.single(commentText, ConstraintFactory.getCommentConstraints().comment)){ pop.error('Invalid Data', 'Thats not a valid comment, I guess'); return; } CommentService.addComment(review.id, {comment: commentText}) .then( function(data) { vm.restaurant.comments.loadComments(review).then(function(){ $('[data-id="'+review.id+'"] #comment-input').val(''); }); }, function(error) { if(error.status === 400){ pop.error('Error', error.data.message); } } ); },
.add('validate.js (str)', function () { validatejs.single(str, validatejsStr) })
.add('validate.js (num)', function () { validatejs.single(num, validatejsNum) })
// var percentageValidate = validate.single(99, coc.percentage); // console.log("percentage: " + percentageValidate); // // var passwordValidate = validate.single("199122", coc.password); // console.log("passwordValidate: " + passwordValidate); // // var latitudeValidate = validate.single("90", coc.latitude); // console.log("latitudeValidate: " + latitudeValidate); // // var longtitudeValidate = validate.single("180", coc.longtitude); // console.log("longtitudeValidate: " + longtitudeValidate); // // var unsignIntegerValidate = validate.single("-111122", coc.unsigned_integer); // console.log("unsignIntegerValidate: " + unsignIntegerValidate); // var emailValidate = validate.single("khanh.huynhdkhanh.huynhddddddddddgkhanh.huynhddddddddddgkhanh.huynhddddddddddgkhanh.huynhddddddddddgkhanh.huynhddddddddddgkhanh.huynhddddddddddgkhanh.huynhddddddddddgkhanh.huynhddddddddddgkhanh.huynhddddddddddgkhanh.huynhddddddddddgkhanh.huynhddddddddddgkhanh.huynhddddddddddgkhanh.huynhddddddddddgkhanh.huynhddddddddddgkhanh.huynhddddddddddgdddddddddgmail.com", coc.email); console.log("emailValidate: " + JSON.stringify(emailValidate)); // // var colorValidate = validate.single("#ffffff", coc.color); // console.log("colorValidate: " + colorValidate); // // var phoneCons = {}; // phoneCons.phone = coc.phone; var phoneValidate = validate.single("11DFGFDHFGHGFHFGHGFHGF11111111", coc.phone); console.log("phoneValidate: " + JSON.stringify(phoneValidate)); // // var textValidate = validate.single("ddd", coc.text); // console.log("textValidate: " + textValidate); // // var urlValidate = validate.single("http://google.com.vn", coc.url); // console.log("urlValidate: " + urlValidate);
isValid: function (value, options) { var errors = validatejs.single(value, processOptions(options)) || []; return errors.length === 0; },
JsonValidator.prototype.validateUrl = function(data) { return validator.single(data, constraints.url); }
JsonValidator.prototype.validateText = function(data) { return validator.single(data, constraints.text); }
JsonValidator.prototype.validateLatitude = function(data) { return validator.single(data, constraints.latitude); }
JsonValidator.prototype.validatePassword = function(data) { return validator.single(data, constraints.password); }
JsonValidator.prototype.validatePercentage = function(data) { return validator.single(data, constraints.percentage); }
JsonValidator.prototype.validateUnsignInteger = function(data) { return validator.single(data, constraints.unsigned_integer); }
JsonValidator.prototype.validateEmail = function(data) { return validator.single(data, constraints.email); }
JsonValidator.prototype.validateColor = function(data) { return validator.single(data, constraints.color); }
JsonValidator.prototype.validatePhoneNumber = function(data) { return validator.single(data, constraints.phone); }