Skip to content

Documentation for implementing md-input-date with DS.attr('date') #764

@queenvictoria

Description

@queenvictoria

Is your feature request related to a problem? Please describe.
When I implement md-input-date with DS.attr('date') I cannot successfully store and retrieve a date.

Describe the solution you'd like
I'd like md-input-date to work well with DS.attr('date').

Describe alternatives you've considered
I've instead implemented a new transform that works with my Mongo backend date format. Mongo accepts an ISODate formatted date.

Here is my model.

import DS from 'ember-data';

export default DS.Model.extend({
  expires: DS.attr('isodate'),
});

Here is my transform ($ ember g transform isodate)

// transforms/isodate.js
import DS from 'ember-data';
import moment from 'moment';

export default DS.Transform.extend({

  materializeDateFormat: 'D MMMM, YYYY',

  // Load from Store.
  deserialize(serialized) {
    return moment(serialized).format(this.materializeDateFormat)
  },

  // Saving to Store.
  serialize(deserialized) {
    return moment(deserialized, this.materializeDateFormat);
  }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions