0

I've got an Ember JS component that is supposed to render a text input with a formatted date. Here is the code I currently have:

import Ember from 'ember';

export default Ember.TextField.extend({
  _value: null,
  value: Ember.computed('_value', {
    get() {
      const value = this.get('_value');

      if (value) {
        return moment(value).format('L HH:mm');
      }

    },
    set(key, value) {
      this.set('_value', value);
      return this.get('value');
    }
  })
});

called with something like {{datetime-input value=model.updatedAt}}

This renders the input fine, and I can verify via the Ember Inspector that the value property is the formatted datetime, but the actual visible content of the input remains the raw, unformatted datetime value. What am I missing?

Asherlc
  • 1,111
  • 2
  • 12
  • 28
  • have you tried this with a normal component ? – engma Jun 24 '15 at 22:14
  • @engma yes, and the same thing happens. it's almost as if the actual `value` property of the component is never getting read, just the value that is passed in as a parameter. – Asherlc Jun 24 '15 at 22:48
  • even with attributeBinding:['value:value'] ? try in on a normal component – engma Jun 24 '15 at 23:15
  • I would move the momentjs logic to a handlebars helper and keep the value as is. You shouldn't be needing to handle `get` and `set` – Patsy Issa Jun 25 '15 at 09:07
  • @Kitler is it possible to use a helper in an input? I want to be able handling user input as well as displaying the value. – Asherlc Jun 25 '15 at 16:28

0 Answers0