Vote count:
0
What I want
I have a model/store/form combination boiling down to:
Field Name Type UI Control
isAllDay bool Checkbox
startDate date DateField
endDate date DateField
startTime date TimeField
endTime date TimeField
If isAllDay
is checked, I set both TimeFields to midnight.
But furthermore, I have to get the endDate field to show one day earlier; because "from Tue to Tue" means "the 24 hours between Tue midnight and Wed midnight" and "from Mon to Fri" means "between Mon midnight and Sat midnight".
So, isAllDay from Tue 09/30/14 to Tue 09/30/14 should be submitted as from 2014-09-30 0:00 to 2014-10-01 0:00.
What I did
I tried to build convert()
and serialize()
functions into the the model:
dateFormat: 'Y-m-d',
name: 'endDate',
type: 'date'
...
name:'isAllDay',
type:'boolean',
convert:function(v, rec) {
if(v==true) {
rec.set("endDate",Ext.Date.add(rec.get("endDate"),Ext.Date.DAY,-1));
}
return v;
},
serialize:function(v, rec) {
if(v==true) {
rec.set("endDate",Ext.Date.add(rec.get("endDate"),Ext.Date.DAY,1));
}
return v;
}
The convert function works like a charm; it even seems to work TOO good, the serialize function doesn't work at all.
- I am sent
isAllDay:true, startDate:2014-10-02, endDate:2014-10-03
- convert makes that
isAllDay:true, startDate:2014-10-02, endDate:2014-10-02
, which I see in the form - I don't change the values in the form
- the record in the store is updated from the form
- now the record contains
isAllDay:true, startDate:2014-10-02, endDate:2014-10-01
! - then the store is synced, sending 2014-10-01 to the server
What exactly is going wrong here? Why isn't "serialize" called, but "convert" is, obviously, called twice?
change a date value depending on a bool
Aucun commentaire:
Enregistrer un commentaire