Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
queenvictoria opened this issue Jun 5, 2019 · 0 comments
Open

Comments

@queenvictoria
Copy link
Contributor

queenvictoria commented Jun 5, 2019

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);
  }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant