Ghost/ghost/admin/app/components/gh-form-group.js
Hannah Wolfe 09bcbb9463 Form field icons load in default 'grey' state
ref #5652

- validations can be in default, success or error state
- adds check for 'hasValidated' if the validations haven't fired yet, the field is in the default state
- hasValidated is an Ember.Array which tracks the state for each field
2015-09-01 13:02:27 +01:00

33 lines
1.0 KiB
JavaScript

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: '',
hasValidated: Ember.A(),
errorClass: Ember.computed('errors.[]', 'property', 'hasValidated.[]', function () {
var property = this.get('property'),
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 '';
}
if (errors) {
return errors.get(property) ? 'error' : 'success';
}
})
});