Skip to content

Instantly share code, notes, and snippets.

@aaronbhansen
Created May 15, 2016 22:25
Show Gist options
  • Save aaronbhansen/f12dca7fdb5d81db7ad98bce44e641b3 to your computer and use it in GitHub Desktop.
Save aaronbhansen/f12dca7fdb5d81db7ad98bce44e641b3 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