Permalink
Browse files

Make the component retrieve the label, help and placeholder automatic…

…ally

using the model name and attribute name passed
  • Loading branch information...
corrspt committed Nov 19, 2016
1 parent 17e65a7 commit f4a15598e405d1eb5456bad4cf734c0d803108fc
Showing with 36 additions and 5 deletions.
  1. +33 −1 app/components/attribute-text.js
  2. +0 −4 app/templates/application.hbs
  3. +3 −0 app/templates/components/attribute-text.hbs
@@ -1,4 +1,36 @@
import Ember from 'ember';
export default Ember.Component.extend({
const {
Component,
inject: { service },
computed,
} = Ember;
export default Component.extend({
i18n: service(),
attribute: '',
getTranslation(property) {
return this.get('i18n').t(`model.${this.get('modelName')}.${this.get('attribute')}.${property}`);
},
modelName: computed.alias('model.constructor.modelName'),
helpText: computed('i18n.locale', function() {
return this.getTranslation('help').toString();
}),
label: computed('i18n.locale', function() {
return this.getTranslation('label').toString();
}),
hasHelp: computed('helpText', function() {
return this.get('helpText').length > 0;
}),
placeholder: computed('i18n.locale', function() {
return this.getTranslation('placeholder').toString();
})
});
@@ -7,8 +7,6 @@
attribute-text
model=model
attribute='name'
label=(t 'model.person.name.label')
placeholder=(t 'model.person.name.placeholder')
onUpdateValue=(action 'setName')
}}
</div>
@@ -17,8 +15,6 @@
attribute-text
model=model
attribute='age'
label=(t 'model.person.age.label')
placeholder=(t 'model.person.age.placeholder')
onUpdateValue=(action 'setAge')
}}
</div>
@@ -10,5 +10,8 @@
type='text'
id={{attribute}}
>
{{#if hasHelp}}
<span class="help-block">{{helpText}}</span>
{{/if}}
</div>

0 comments on commit f4a1559

Please sign in to comment.