Skip to content

Instantly share code, notes, and snippets.

@jhliberty
Forked from aaronbhansen/component.js
Created May 17, 2016 17:31
Show Gist options
  • Save jhliberty/0dd9fe129c9b30dad4b967811fb5d948 to your computer and use it in GitHub Desktop.
Save jhliberty/0dd9fe129c9b30dad4b967811fb5d948 to your computer and use it in GitHub Desktop.
UI Field helper {{ui-field}}
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['field'],
classNameBindings: ['is_error:error'],
model: null, // Model object being passed in
property: null, // The specific property on the model to look for
submitted: false,
show_error: true,
didInitAttrs() {
Ember.defineProperty(this, 'is_error', Ember.computed('submitted',`model.validations.attrs.${this.get('property')}.isTruelyValid`, function() {
if (this.get('submitted')) {
let valid = this.get(`model.validations.attrs.${this.get('property')}.isTruelyValid`);
if (typeof valid === "boolean") {
this.set(`model.validations.attrs.${this.get('property')}.fieldObserved`, true);
return !valid;
}
}
return false;
}));
}
});
{{yield is_error}}
{{#if show_error}}{{#if is_error}}
<div class="ui basic red pointing prompt label transition visible">
{{v-get model property "message"}}
</div>
{{/if}}{{/if}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment