Here is an example for a input field with type=“date”. The goal/problem was to bind the value of the input field directly to a non-String value. In this case it’s a normal Date object.
App.DateField = Ember.TextField.extend({
type: 'date',
date: function() {
var value = this.get('value');
if (value) {
return new Date(value)); //You probably want to validate the date in some way
} else {
return null;
}
}.property('value')
});
I wanted something that does only change the date if the text value can be parsed by Date.parse(). As a side effect, now you can also type “2012” and it yields to “2012-01-01” on blur, which is kinda cool. – Of course this only comes into effect on browsers that do not support date input fields (like Firefox).