1. #1
    Sencha User murrah's Avatar
    Join Date
    Oct 2007
    Location
    Katoomba, Blue Mountains, west of Sydney, Australia
    Posts
    383
    Vote Rating
    11
    murrah will become famous soon enough

      0  

    Default Solved - Form date field - format different to model causes empty date to be saved

    Solved - Form date field - format different to model causes empty date to be saved


    Hi,

    Using Ext.data.proxy.Rest, consuming a field that comes in this format:
    PHP Code:
    {name'datejoined'type:'date'dateFormat:'Y-m-d H:i:s'
    displays in grid correctly.

    Edit the grid record using a form with the date field of:
    PHP Code:
    {
        
    xtype'datefield',
        
    name'datejoined',
        
    fieldLabel'Date joined',
        
    format'd/m/Y',
        
    altFormat'Y-m-d H:i:s' // Just tried this on the off chance, but it didnt help the problem
    }, 
    The date displays correctly.

    BUT... if I save the form which gets me to here in my controller:
    PHP Code:
    var win button.up('window'),
        
    form win.down('form'),
        
    record form.getRecord(),
        
    values form.getValues();

    record.set(values); 
    The date ends up as an empty string in the record:
    record.set(values) --> field.convert(value, me); --> Ext.Date.parse(v, df);

    The reason is that Ext.Date.parse fails because the string from the form field value (v) is in the format 'd/m/Y' while the date format (df) uses the model field's dateFormatof 'Y-m-d H:i:s'!

    It seems strange that I cant display a form field date in any format I choose and have the record.set() method use the form field's format to convert to a date object!

    My work around is as follows:
    PHP Code:
    var win button.up('window'),
        
    form win.down('form'),
        
    record form.getRecord(),
        
    values form.getValues();

    var 
    fld form.getForm().findField('datejoined');
    var 
    fldFormat fld.format;
    values.datejoined Ext.Date.parse(values.datejoinedfldFormat);

    record.set(values); 
    That works because I am taking care of the conversion myself before record.set() gets it. (The date is then correctly converted to the ''Y-m-d H:i:s' by the writer before being sent to the server).

    So, am I configuring something incorrectly, or is this a bug?

    Thanks,
    Murray
    Last edited by murrah; 19 Jul 2012 at 1:41 PM. Reason: Added Solved

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,918
    Vote Rating
    443
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    The value send to the server should be in the format specified your proxy. You should not have to parse it manually. IIRC, I noticed the same behavior .. the record header had blank dates?

    I will take a closer look.

    Scott.

  3. #3
    Sencha User murrah's Avatar
    Join Date
    Oct 2007
    Location
    Katoomba, Blue Mountains, west of Sydney, Australia
    Posts
    383
    Vote Rating
    11
    murrah will become famous soon enough

      0  

    Default


    Thanks Scott!

  4. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,918
    Vote Rating
    443
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    After testing this .. you should be able to set useDataValues:true in getValues() to make this work as expected.

    Scott.

  5. #5
    Sencha User murrah's Avatar
    Join Date
    Oct 2007
    Location
    Katoomba, Blue Mountains, west of Sydney, Australia
    Posts
    383
    Vote Rating
    11
    murrah will become famous soon enough

      0  

    Default


    Thanks Scott. I am just getting up to speed with Ext 4 having last used Ext 3 some time ago, so I missed that new method and options. That is much better! All good now.

    Thanks again for your help,
    Murray

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi