简体   繁体   中英

call an ember handlebars helper within an input helper

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM