ac9f269085
closes #3153 - this is all about the validation engine - add a option, `opts.model`, to use a passed-in model directly if needed - handle validators that return an array of strings, array of objects, or both - ajax util returns either an array of errors or a single concat'd string - remove formatErrors function from the mixin and make it private - allow validation options to be passed into `.save()` since ember-data doesn't take params on `.save()` anyway - streamline control flow
34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
var SettingValidator = Ember.Object.create({
|
|
check: function (model) {
|
|
var validationErrors = [],
|
|
title = model.get('title'),
|
|
description = model.get('description'),
|
|
email = model.get('email'),
|
|
postsPerPage = model.get('postsPerPage');
|
|
|
|
if (!validator.isLength(title, 0, 150)) {
|
|
validationErrors.push({ message: 'Title is too long' });
|
|
}
|
|
|
|
if (!validator.isLength(description, 0, 200)) {
|
|
validationErrors.push({ message: 'Description is too long' });
|
|
}
|
|
|
|
if (!validator.isEmail(email) || !validator.isLength(email, 0, 254)) {
|
|
validationErrors.push({ message: 'Please supply a valid email address' });
|
|
}
|
|
|
|
if (!validator.isInt(postsPerPage) || postsPerPage > 1000) {
|
|
validationErrors.push({ message: 'Please use a number less than 1000' });
|
|
}
|
|
|
|
if (!validator.isInt(postsPerPage) || postsPerPage < 0) {
|
|
validationErrors.push({ message: 'Please use a number greater than 0' });
|
|
}
|
|
|
|
return validationErrors;
|
|
}
|
|
});
|
|
|
|
export default SettingValidator;
|