Ghost/ghost/admin/app/validators/setting.js
Austin Burdine b1ecc53cfc adds inline errors to validation
closes #5336
- creates gh-form-group component to handle form group status
- refactors current validation methods to work on a per-property basis
- adds gh-error-message component to render error message
- removes (comments out) tests that pertain to the old notifications until the new inline validation is added
2015-07-05 14:02:06 -04:00

51 lines
1.6 KiB
JavaScript

import BaseValidator from './base';
var SettingValidator = BaseValidator.create({
properties: ['title', 'description', 'password', 'postsPerPage'],
title: function (model) {
var title = model.get('title');
if (!validator.isLength(title, 0, 150)) {
model.get('errors').add('title', 'Title is too long');
this.invalidate();
}
},
description: function (model) {
var desc = model.get('description');
if (!validator.isLength(desc, 0, 200)) {
model.get('errors').add('description', 'Description is too long');
this.invalidate();
}
},
password: function (model) {
var isPrivate = model.get('isPrivate'),
password = this.get('password');
if (isPrivate && password === '') {
model.get('errors').add('password', 'Password must be supplied');
this.invalidate();
}
},
postsPerPage: function (model) {
var postsPerPage = model.get('postsPerPage');
if (postsPerPage > 1000) {
model.get('errors').add('postsPerPage', 'The maximum number of posts per page is 1000');
this.invalidate();
}
if (postsPerPage < 1) {
model.get('errors').add('postsPerPage', 'The minimum number of posts per page is 1');
this.invalidate();
}
if (!validator.isInt(postsPerPage)) {
model.get('errors').add('postsPerPage', 'Posts per page must be a number');
this.invalidate();
}
}
});
export default SettingValidator;