2018-10-18 02:18:29 +03:00
|
|
|
import BaseValidator from './base';
|
2019-01-22 16:09:38 +03:00
|
|
|
import validator from 'validator';
|
2018-10-18 02:18:29 +03:00
|
|
|
import {isBlank} from '@ember/utils';
|
|
|
|
|
|
|
|
export default BaseValidator.create({
|
|
|
|
properties: ['name'],
|
|
|
|
|
|
|
|
name(model) {
|
|
|
|
if (isBlank(model.name)) {
|
|
|
|
model.errors.add('name', 'Please enter a name');
|
|
|
|
model.hasValidated.pushObject('name');
|
|
|
|
this.invalidate();
|
|
|
|
} else if (!validator.isLength(model.name, 0, 191)) {
|
|
|
|
model.errors.add('name', 'Name is too long, max 191 chars');
|
|
|
|
model.hasValidated.pushObject('name');
|
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|