mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 18:31:57 +03:00
e376ef0242
closes https://github.com/TryGhost/Ghost/issues/15290 - Capture error from model errors - Add hasValidated for name property to properly mark field as error/success - Add property to hasValidated after each failed validation - Wrap saving on try-catch to suppress uncaught exception (validation error)
20 lines
579 B
JavaScript
20 lines
579 B
JavaScript
import BaseValidator from './base';
|
|
import validator from 'validator';
|
|
|
|
export default BaseValidator.create({
|
|
properties: ['name'],
|
|
|
|
name(model) {
|
|
if (!model.name) {
|
|
model.errors.add('name', 'Please enter Name.');
|
|
model.hasValidated.addObject('name');
|
|
this.invalidate();
|
|
}
|
|
if (!validator.isLength(model.name || '', 0, 191)) {
|
|
model.errors.add('name', 'Name cannot be longer than 191 characters.');
|
|
model.hasValidated.addObject('name');
|
|
this.invalidate();
|
|
}
|
|
}
|
|
});
|