Reputation: 2024
I can't figure out the right way to call an Ember.Handlebars.registerBoundHelper within an Ember input-helper.
The BoundHelper does a date formatting:
Ember.Handlebars.registerBoundHelper('formattedDate', function(date) {
return moment(date).format('DD.MM.YYYY');
});
I can call the helper in a template and get a formatted date:
{{formattedDate 'myUnformattedDate}}
Now I would like to call this helper within an input-helper similar to this:
{{input type="text" value=orderDate id="orderDate" placeholder="{{formattedDate orderDate}}" }}
Is calling a helper within a helper even possible in Ember?
-- Update
I'm developing in Ember version 1.7.0
Upvotes: 3
Views: 1135
Reputation: 2592
You can extend Ember.TextField
to create your own date-input
by doing something like
App.DateInputComponent = Ember.TextField.extend({
format: 'DD.MM.YYYY',
date: function(key, date) {
var format = this.get('format');
if (date) {
this.set('value', moment(date).format(format));
} else {
value = this.get('value');
if (value) {
date = moment(value, format);
} else {
date = null;
}
}
return date;
}.property('value')
});
and then in your template you can do...
{{date-input date=date}}
OR
{{date-input date=date format="MM/DD/YYYY"}}
You can see a working bin here: http://emberjs.jsbin.com/vosen/1/edit
For further discussion see: http://discuss.emberjs.com/t/example-building-a-date-input-field/674/4
Upvotes: 3