Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate an input type="date" in Ember
    primarykey
    data
    text
    <p>I'm trying to create an <code>&lt;input type="date"/&gt;</code> in Emberjs and I have two problems:</p> <ol> <li>In my country the date is displayed as DD-MM-YYYY format while the date field requires a MM-DD-YYYY format (and then the browser displays it according to its locale). So the date should be formatted in one way if the browser supports the date input field and in the other way if not</li> <li>The date is bound to a Date object</li> </ol> <p>I'm using Momentjs for formatting and Ember Data.</p> <p>I'm trying to extend Ember.TextField like this:</p> <pre><code>App.DateField = Ember.TextField.extend value: ( (key, value) -&gt; 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' </code></pre> <p>For browsers with date input supports this works. For the other browsers the date is correctly displayed, but it is saved as a (wrong formatted) string in the model.</p> <p>How can I maintain the correct formatting while still using Date objects in the backend?</p> <p><a href="http://jsfiddle.net/guybrushthreepwood/zRzxp/" rel="noreferrer">Demo</a></p> <p><strong>Update</strong></p> <p>Thanks to the blog post provided in the accepted answer I was able to update the demo to do what I want (with some weirdnesses, but not relevant at this time)</p> <p><a href="http://jsfiddle.net/guybrushthreepwood/zRzxp/9/" rel="noreferrer">Demo2</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload