Date as day, month, year fields
Hi!
I have database which stores dates as three integer fields 'day', 'month' and 'year'. I use ExtJS to present this to the user and would like to use this awesome datepicker. I tried to have a model with field 'date' by using convert method and also by overriding getters and setters, non of this worked. It appears that convert works only one way (it works great for parsing data from server but that's all, i can't save changes) and setters are never used so that the changes do not persist. Is there a way to change these three fields into one and vice versa using ExtJS or should I just do it manually on server side application?
Code:
Ext.define('App.model.ModelWithDate', {
extend: 'Ext.data.Model',
fields: [
{name: 'day', type: 'int'},
{name: 'month', type: 'int'},
{name: 'year', type: 'int'},
{name: 'date' , type: 'date', convert: convertDate, persist: false}
],
applyDate: function(date) {
alert(JSON.stringify(date));
this.year = date.getYear();
this.month = date.getMonth();
this.day = date.getDay();
},
getDate: function() {
alert(this);
return new Date(this.year, this.month, this.day, 0, 0, 0, 0);
},
setDate: function(date) {
alert(JSON.stringify(date));
this.year = date.getYear();
this.month = date.getMonth();
this.day = date.getDay();
}
});
function convertDate(v, record){
alert(JSON.stringify(record.data));
return new Date(record.data.year, record.data.month, record.data.day, 0, 0, 0, 0);
}