vendredi 3 juin 2016

Ember child component updates parent component model only on click

I got this form-component, with a datepicker sub-component within, based on Pikaday.

In the form-component I've got an observer for datepicker's value:

// form-component.hbs



// form-component.js
testDueDate: function() {
  console.log(this.get('model.dueDate'));
}.observes('model.dueDate');

// date-picker.js
testDatepickerValue: function() {
  console.log(this.get('value'));
}.observes('value');

// Only triggers date-picker's observer, but not the one from form-component:
this.set('value', new Date());

When I manually pick a date (that is, opening the datepicker and clicking on any date with the mouse), everything works fine: both testDueDate() and testDatepickerValue() fire and display the given date.

But when I programatically set the date (that is, via Pikalendar API), the parent component's observer won't fire, even though the one in the datepicker do and shows value has changed.

By looking at Pikalendar's code I can see that both clicking on a date and programatically setting the date use the setDate() function, so, from there on, everything should trigger the same functions.

Somehow, form component only updates value when calendar is clicked.

Any ideas on what may I be doing wrong?

Thanks!




Aucun commentaire:

Enregistrer un commentaire