2015-09-16 20:02:06 +03:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
const {Mixin, computed, isEmpty} = Ember;
|
|
|
|
const emberA = Ember.A;
|
|
|
|
|
|
|
|
export default Mixin.create({
|
2015-09-16 20:02:06 +03:00
|
|
|
|
|
|
|
errors: null,
|
|
|
|
property: '',
|
2015-10-28 14:36:45 +03:00
|
|
|
hasValidated: emberA(),
|
2015-09-16 20:02:06 +03:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
hasError: computed('errors.[]', 'property', 'hasValidated.[]', function () {
|
|
|
|
let property = this.get('property');
|
|
|
|
let errors = this.get('errors');
|
|
|
|
let hasValidated = this.get('hasValidated');
|
2015-09-16 20:02:06 +03:00
|
|
|
|
|
|
|
// if we aren't looking at a specific property we always want an error class
|
2015-10-28 14:36:45 +03:00
|
|
|
if (!property && !isEmpty(errors)) {
|
2015-09-16 20:02:06 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we haven't yet validated this field, there is no validation class needed
|
|
|
|
if (!hasValidated || !hasValidated.contains(property)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (errors) {
|
|
|
|
return errors.get(property);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
})
|
|
|
|
|
|
|
|
});
|