Ghost/ghost/admin/app/validators/nav-item.js
Kevin Ansfield e74e2e039e Update code to match eslint rules
no issue
- switch `jscs` and `jshint` inline config to `eslint` config
- fix eslint errors, predominantly in tests where the config now the main app config more closely
2016-11-14 13:26:00 +00:00

37 lines
1.1 KiB
JavaScript

import BaseValidator from './base';
export default BaseValidator.create({
properties: ['label', 'url'],
label(model) {
let label = model.get('label');
let hasValidated = model.get('hasValidated');
if (validator.empty(label)) {
model.get('errors').add('label', 'You must specify a label');
this.invalidate();
}
hasValidated.addObject('label');
},
url(model) {
let url = model.get('url');
let hasValidated = model.get('hasValidated');
/* eslint-disable camelcase */
let validatorOptions = {require_protocol: true};
/* eslint-enable camelcase */
let urlRegex = new RegExp(/^(\/|#|[a-zA-Z0-9\-]+:)/);
if (validator.empty(url)) {
model.get('errors').add('url', 'You must specify a URL or relative path');
this.invalidate();
} else if (url.match(/\s/) || (!validator.isURL(url, validatorOptions) && !url.match(urlRegex))) {
model.get('errors').add('url', 'You must specify a valid URL or relative path');
this.invalidate();
}
hasValidated.addObject('url');
}
});