mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 03:12:54 +03:00
9b6214b9ad
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
33 lines
1.0 KiB
JavaScript
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';
|
|
}
|
|
})
|
|
});
|