Bump not sending date attribute

I have an attribute date

in my Ember model:

// models/foo.js
export default DS.Model.extend({
  name: attr('string'),
  startDate: attr('date')
});

      

My component sets the date in ISO 8601 format as a convention :

// components/date-picker.js
export default Ember.Component.extend({
...
picker.on({
  set: function(timestamp) {
    // timestamp.select is a unix timestamp
    var date = new Date(timestamp.select);
    var iso = date.toISOString();       
    self.set('property', iso);
  }
});
...

      

And I can see that this is reflected in Amber's inspector:

Ember Inspector

However, when Ember sends data to my server, startDate

there is null

.

Does anyone have an idea why this might be?

+3


source to share


1 answer


The date conversion expects your property to be the client side of the date object, not a string. It checks when it serializes it to be an instance of Date.

serialize: function(date) {
  if (date instanceof Date) {
    return toISOString.call(date);
  } else {
    return null;
  }
}

      



Better to disable the property of the date object and let it be called toISOString

when it serializes it to send to the server.

+2


source







All Articles