Call the helper helper ember inside the input helper

I can't find the correct way to call Ember.Handlebars.registerBoundHelper inside Ember input-helper.

BoundHelper does date formatting:

Ember.Handlebars.registerBoundHelper('formattedDate', function(date) {
   return moment(date).format('DD.MM.YYYY');
});

      

I can call the helper in the template and get the formatted date:

{{formattedDate 'myUnformattedDate}}

      

Now, I would like to call this helper inside the input helper like this:

{{input type="text" value=orderDate id="orderDate" placeholder="{{formattedDate orderDate}}" }}

      

Does the helper call inside the helper even in Ember?

- Update

I am developing in Ember version 1.7.0

+3


source to share


1 answer


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 the working drive 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

+3


source







All Articles