2015-11-18 13:50:48 +03:00
|
|
|
import BaseValidator from './base';
|
2019-01-22 16:09:38 +03:00
|
|
|
import validator from 'validator';
|
2018-03-19 20:56:09 +03:00
|
|
|
import {isBlank} from '@ember/utils';
|
2015-11-18 13:50:48 +03:00
|
|
|
|
|
|
|
export default BaseValidator.create({
|
2018-12-10 17:26:05 +03:00
|
|
|
properties: ['email', 'role'],
|
2015-11-18 13:50:48 +03:00
|
|
|
|
|
|
|
email(model) {
|
|
|
|
let email = model.get('email');
|
|
|
|
|
2018-03-19 20:56:09 +03:00
|
|
|
if (isBlank(email)) {
|
2015-11-18 13:50:48 +03:00
|
|
|
model.get('errors').add('email', 'Please enter an email.');
|
|
|
|
this.invalidate();
|
|
|
|
} else if (!validator.isEmail(email)) {
|
|
|
|
model.get('errors').add('email', 'Invalid Email.');
|
|
|
|
this.invalidate();
|
|
|
|
}
|
2018-12-10 17:26:05 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
role(model) {
|
|
|
|
let role = model.get('role');
|
|
|
|
|
|
|
|
if (isBlank(role)) {
|
|
|
|
model.get('errors').add('role', 'Please select a role.');
|
|
|
|
model.get('hasValidated').pushObject('role');
|
|
|
|
this.invalidate();
|
|
|
|
}
|
2015-11-18 13:50:48 +03:00
|
|
|
}
|
|
|
|
});
|