mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 08:31:43 +03:00
786e0ac9c5
no issue - if a plain native class instance with tracked properties is validated against the `ValidationEngine` and it's associated validators would cause errors by assuming that the instance has a `.get()` method - updated all model access in `ValidationEngine` and the validators to use direct property access which works for both native class and `EmberObject` instances
32 lines
838 B
JavaScript
32 lines
838 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.hasValidated.addObject('name');
|
|
},
|
|
|
|
mobiledoc(model) {
|
|
if (isBlank(model.mobiledoc)) {
|
|
model.errors.add('mobiledoc', 'Content cannot be blank.');
|
|
this.invalidate();
|
|
}
|
|
model.hasValidated.addObject('mobiledoc');
|
|
}
|
|
});
|