Ghost/ghost/admin/app/validators/tier.js
Hakim Razalan e376ef0242
🐛 Fixed Hidden error in "Add tier" modal (#15361)
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)
2022-09-13 09:23:54 +01:00

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();
}
}
});