-
26 Dec 2010 9:22 PM #1
Override default dateFormat
Override default dateFormat
Hi,
I'm trying to set some global defaults so I don't have to specify a reader for every form, as well as not mentioning the dateFormat for every DateField.
The code I currently use, (and would think is correct as well) is this:
However, when I load my forms without setting a reader my DateFields do get the correct date (in the correct format), but as time they always get 0:00. Enabling the reader (code below) fixes this problem.PHP Code:Ext.apply(Ext.form.DateField.prototype, {
format: 'd-m-Y G:i'
});
Ext.apply(Ext.data.Field.prototype, {
dateFormat: 'U'
});
Any ideas why the DateField override works, and the Field override doesn't?PHP Code:reader: new Ext.data.JsonReader({
root: function(v) {
return v.data ? [v.data] : [];
},
successProperty: 'success',
fields: [{
name: 'model'
},{
name: 'id', type: 'int'
},{
name: 'filename'
},{
name: 'owner'
},{
name: 'created', type: 'date', dateFormat: 'U'
},{
name: 'modified', type: 'date', dateFormat: 'U'
},{
name: 'revision'
},{
name: 'published', type: 'bool'
}]
})
Thanks in advance!Last edited by KristofTorfs; 26 Dec 2010 at 9:24 PM. Reason: Added some more info
-
26 Dec 2010 11:05 PM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
1. A DateField isn't meant to be used for time editing.
2. If you load a form without a reader, it will try to initialize the fields with the raw values from the server (in 'U' format in your case).
Your datafield will need to contain (at least) 'U' in its 'altFormats' config option to be able to interpret that value.
-
26 Dec 2010 11:18 PM #3
For your first point, I actually didn't think about that at all, considering the fields are read-only

However, I tried specifying 'U' in altFormats and this didn't help either. Am I to understand that the DateField just isn't sufficient when handling times, even for displaying? I'll just have to take a look at which field(s) I'd use best.
One more question though: the code I used to change the Ext.data.Field prototype is correct? So if should decide to change the format of dates in my PHP backend, I would only have to change it there, and my entire application would remain function.
-
26 Dec 2010 11:41 PM #4Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
DateField detects if the format contains 'g', 'G', 'h' or 'H' to determine if time should be parsed. Unfortunately, it doesn't take 'U' into account, so it assumes it should only parse the date and not the time. I created a bugreport for this..
Yes, but do remember that you still have to specify type:'date' for all date fields.
Similar Threads
-
Can't Override Default ToolTip Delay
By ccocco_dw in forum Ext GWT: DiscussionReplies: 5Last Post: 7 Dec 2010, 4:23 AM -
Override default AJAX error handler
By Perceptive in forum Ext 3.x: Help & DiscussionReplies: 2Last Post: 24 Sep 2010, 6:06 AM -
Override default config values, is it possible?
By webgunz in forum Ext 2.x: Help & DiscussionReplies: 2Last Post: 24 Dec 2007, 11:38 AM


Reply With Quote