1. #1
    Sencha User
    Join Date
    Dec 2007
    Posts
    3
    Vote Rating
    0
    KristofTorfs is on a distinguished road

      0  

    Question 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:

    PHP Code:
    Ext.apply(Ext.form.DateField.prototype, {
        
    format'd-m-Y G:i'
    });
    Ext.apply(Ext.data.Field.prototype, {
        
    dateFormat'U'
    }); 
    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:
    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'
        
    }]
    }) 
    Any ideas why the DateField override works, and the Field override doesn't?

    Thanks in advance!
    Last edited by KristofTorfs; 26 Dec 2010 at 9:24 PM. Reason: Added some more info

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    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.

  3. #3
    Sencha User
    Join Date
    Dec 2007
    Posts
    3
    Vote Rating
    0
    KristofTorfs is on a distinguished road

      0  

    Default


    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.

  4. #4
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Quote Originally Posted by KristofTorfs View Post
    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.
    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..

    Quote Originally Posted by KristofTorfs View Post
    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.
    Yes, but do remember that you still have to specify type:'date' for all date fields.

Similar Threads

  1. Can't Override Default ToolTip Delay
    By ccocco_dw in forum Ext GWT: Discussion
    Replies: 5
    Last Post: 7 Dec 2010, 4:23 AM
  2. Override default AJAX error handler
    By Perceptive in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 24 Sep 2010, 6:06 AM
  3. Override default config values, is it possible?
    By webgunz in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 24 Dec 2007, 11:38 AM

Thread Participants: 1

Tags for this Thread