mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 22:43:30 +03:00
b1ecc53cfc
closes #5336 - creates gh-form-group component to handle form group status - refactors current validation methods to work on a per-property basis - adds gh-error-message component to render error message - removes (comments out) tests that pertain to the old notifications until the new inline validation is added
35 lines
1.0 KiB
JavaScript
35 lines
1.0 KiB
JavaScript
import Ember from 'ember';
|
|
|
|
/**
|
|
* Renders one random error message when passed a DS.Errors object
|
|
* and a property name. The message will be one of the ones associated with
|
|
* that specific property. If there are no errors associated with the property,
|
|
* nothing will be rendered.
|
|
* @param {DS.Errors} errors The DS.Errors object
|
|
* @param {string} property The property name
|
|
*/
|
|
export default Ember.Component.extend({
|
|
tagName: 'p',
|
|
classNames: ['response'],
|
|
|
|
errors: null,
|
|
property: '',
|
|
|
|
isVisible: Ember.computed.notEmpty('errors'),
|
|
|
|
message: Ember.computed('errors.[]', 'property', function () {
|
|
var property = this.get('property'),
|
|
errors = this.get('errors'),
|
|
messages = [],
|
|
index;
|
|
|
|
if (!Ember.isEmpty(errors) && errors.get(property)) {
|
|
errors.get(property).forEach(function (error) {
|
|
messages.push(error);
|
|
});
|
|
index = Math.floor(Math.random() * messages.length);
|
|
return messages[index].message;
|
|
}
|
|
})
|
|
});
|