2015-06-07 06:19:19 +03:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the CSS necessary to show a specific property state. When passed a
|
|
|
|
* DS.Errors object and a property name, if the DS.Errors object has errors for
|
|
|
|
* the specified property, it will change the CSS to reflect the error state
|
|
|
|
* @param {DS.Errors} errors The DS.Errors object
|
|
|
|
* @param {string} property Name of the property
|
|
|
|
*/
|
|
|
|
export default Ember.Component.extend({
|
|
|
|
classNames: 'form-group',
|
|
|
|
classNameBindings: ['errorClass'],
|
|
|
|
|
|
|
|
errors: null,
|
|
|
|
property: '',
|
2015-08-27 23:28:41 +03:00
|
|
|
hasValidated: Ember.A(),
|
2015-06-07 06:19:19 +03:00
|
|
|
|
2015-08-27 23:28:41 +03:00
|
|
|
errorClass: Ember.computed('errors.[]', 'property', 'hasValidated.[]', function () {
|
2015-06-07 06:19:19 +03:00
|
|
|
var property = this.get('property'),
|
2015-08-27 23:28:41 +03:00
|
|
|
errors = this.get('errors'),
|
|
|
|
hasValidated = this.get('hasValidated');
|
|
|
|
|
|
|
|
// If we haven't yet validated this field, there is no validation class needed
|
|
|
|
if (!hasValidated || !hasValidated.contains(property)) {
|
|
|
|
return '';
|
|
|
|
}
|
2015-06-07 06:19:19 +03:00
|
|
|
|
|
|
|
if (errors) {
|
|
|
|
return errors.get(property) ? 'error' : 'success';
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|