Ghost/ghost/admin/app/validators/snippet.js
2020-10-16 19:22:09 +01:00

32 lines
859 B
JavaScript

import BaseValidator from './base';
import validator from 'validator';
import {isBlank} from '@ember/utils';
export default BaseValidator.create({
properties: ['name', 'mobiledoc'],
name(model) {
let {name} = model;
if (!validator.isLength(name || '', 0, 191)) {
model.errors.add('name', 'Name cannot be longer than 191 characters');
this.invalidate();
}
if (isBlank(name)) {
model.errors.add('name', 'Name cannot be blank');
this.invalidate();
}
model.get('hasValidated').addObject('name');
},
mobiledoc(model) {
if (isBlank(model.get('mobiledoc'))) {
model.errors.add('mobiledoc', 'Content cannot be blank.');
this.invalidate();
}
model.get('hasValidated').addObject('mobiledoc');
}
});