2019-11-28 14:30:21 +03:00
|
|
|
import BaseValidator from './base';
|
|
|
|
import validator from 'validator';
|
|
|
|
import {isBlank} from '@ember/utils';
|
|
|
|
|
|
|
|
export default BaseValidator.create({
|
|
|
|
properties: ['name', 'email', 'note'],
|
|
|
|
|
|
|
|
name(model) {
|
|
|
|
if (!validator.isLength(model.name || '', 0, 191)) {
|
|
|
|
model.errors.add('name', 'Name cannot be longer than 191 characters.');
|
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
email(model) {
|
2022-10-07 22:13:42 +03:00
|
|
|
let email = model.email;
|
2019-11-28 14:30:21 +03:00
|
|
|
|
|
|
|
if (isBlank(email)) {
|
2020-05-11 13:40:38 +03:00
|
|
|
model.errors.add('email', 'Please enter an email.');
|
2019-11-28 14:30:21 +03:00
|
|
|
this.invalidate();
|
|
|
|
} else if (!validator.isEmail(email)) {
|
2020-05-11 13:40:38 +03:00
|
|
|
model.errors.add('email', 'Invalid Email.');
|
2019-11-28 14:30:21 +03:00
|
|
|
this.invalidate();
|
|
|
|
}
|
2020-05-11 13:40:38 +03:00
|
|
|
if (!validator.isLength(model.email || '', 0, 191)) {
|
2019-11-28 14:30:21 +03:00
|
|
|
model.errors.add('email', 'Email cannot be longer than 191 characters.');
|
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
|
2022-10-07 22:13:42 +03:00
|
|
|
model.hasValidated.addObject('email');
|
2019-11-28 14:30:21 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
note(model) {
|
2022-10-07 22:13:42 +03:00
|
|
|
let note = model.note;
|
2019-11-28 14:30:21 +03:00
|
|
|
|
|
|
|
if (!validator.isLength(note || '', 0, 500)) {
|
2020-05-11 13:40:38 +03:00
|
|
|
model.errors.add('note', 'Note is too long.');
|
2019-11-28 14:30:21 +03:00
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
|
2022-10-07 22:13:42 +03:00
|
|
|
model.hasValidated.addObject('note');
|
2019-11-28 14:30:21 +03:00
|
|
|
}
|
|
|
|
});
|