Create input type = "date" in Ember
I am trying to create <input type="date"/> in Emberjs and I have two problems:
- In my country, the date is displayed as DD-MM-YYYY format, while the date field requires the format MM-DD-YYYY (and then the browser displays it according to its locale). Therefore, the date should be formatted in one way, if the browser supports the date input field, otherwise, if not
- Date attached to a Date object
I use Momentjs for formatting and Ember Data.
I am trying to extend Ember.TextField as follows:
App.DateField = Ember.TextField.extend value: ( (key, value) -> if value? if /Date/.test value.constructor #I assume that if the passed value is a Date object then it is arriving directly from the model if Modernizr.inputtypes.date moment(value).format('YYYY-MM-DD') else moment(value).format('DD-MM-YYYY') else # if the passed value is not a Date object then the user is typing into the form if Modernizr.inputtypes.date value = new Date('value') else value ).property() type: 'date' For date enabled browsers this works. For other browsers, the date is displayed correctly, but it is saved as a string (incorrectly formatted) in the model.
How can I maintain proper formatting when using Date objects in the backend?
Update
Thanks to the blog post provided in the accepted answer, I was able to update the demo to do what I want (with some oddities but not relevant at this time)
Take a look at these two blog posts:
This is a simple date picker : http://hawkins.io/2013/06/datepicker-in-ember/ This one uses a bootstrap date picker http://hawkins.io/2013/06/fancy-ember-datepicker-with-twitter- bootstrap /
Hope this helps