Ghost/ghost/admin/app/validators/setup.js
Kevin Ansfield 786e0ac9c5
Updated ValidationEngine to support bare native class models (#15567)
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
2022-10-07 20:13:42 +01:00

21 lines
612 B
JavaScript

import NewUserValidator from 'ghost-admin/validators/new-user';
import validator from 'validator';
export default NewUserValidator.create({
properties: ['name', 'email', 'password', 'blogTitle'],
blogTitle(model) {
let blogTitle = model.blogTitle;
if (!validator.isLength(blogTitle || '', 1)) {
model.errors.add('blogTitle', 'Please enter a site title.');
this.invalidate();
}
if (!validator.isLength(blogTitle || '', 0, 150)) {
model.errors.add('blogTitle', 'Title is too long');
this.invalidate();
}
}
});