Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: how to format value of datefield on submit

  1. #11
    Sencha Premium User alexander.urban's Avatar
    Join Date
    Nov 2013
    Posts
    314
    Answers
    9
    Vote Rating
    49
      0  

    Default

    Please post the code how you submit it. Do you submit the store, the model or the form?

  2. #12
    Sencha User
    Join Date
    Jan 2015
    Posts
    1
    Vote Rating
    0
      0  

    Default

    I have the same problem.
    Code:
    
    Here is my form :
     items: [{
            xtype:'form',
            id:'form',
            jsonSubmit:true,
            width:'40%',
            url:'/webapp-2.1.1-RELEASE/AllComputer/add',
            items:[{
                xtype:'textfield',
                fieldLabel:'Computer Name',
                name:'name',
                allowBlank:false,
                width:'100%'
            }, {
                xtype:'datefield',
                fieldLabel:'Introduced Date',
                name:'introduced',
                format:'d/m/Y',
                submitFormat:'d/m/Y',
                submitValue:true,
                width:'100%'
            },{
                xtype:'datefield',
                fieldLabel:'Discountinued Date',
                name:'discontinued',
                format:'m/d/Y',
                submitFormat:'m/d/Y',
                submitValue:true,
                width:'100%'
            },{
                xtype:'combobox',
                id:'comboBox',
                name:'company',
                fieldLabel:'Company',
                store:'CompanyStore',
                queryMode:'local',
                valueField:'id',
                displayField:'name',
                editable:false,
                allowBlank:false,
                forceSelection:true,
                autoLoadOnValue:true,
                width:'100%',
                submitValue:false
            },{
                xtype:'toolbar',
                width:'100%',
                layout:{
                  pack:'center'
                },
                items:[
                    {
                    xtype:'button',
                    text:'Add',
                    handler:'AddComputer',
                    formBind: true, //only enabled once the form is valid
                    disabled: true
                },{
                    xtype:'component',
                    html:'or'
                },{
                    xtype:'button',
                    text:'Cancel',
                    handler:'Cancel'
                }]
            }]
        }
    and my submit function :
    Code:
    AddComputer:function() {
            var form = Ext.getCmp("form");
            var comboBox = Ext.getCmp("comboBox");
            var id = comboBox.getValue();
            if (form.isValid()) {
                form.submit({
                    params:{
                        company:{id:id,name:""},
                        id:"-1"
                    },
                    success: function(form) {
                        Ext.Msg.alert('Success', "success");
                    },
                    failure: function(form, action) {
                        Ext.Msg.alert('Failed', "fail");
                    }
                });
            }
        }
    When i see the parameter of the submit. I don't have the expect result.
    params request of the sumit launch by Extjs

    {"company":{"id":"0","name":""},"id":"-1","name":"Toto5","introduced":"2015-01-08T00:00:00","discontinued":"2015-01-29T00:00:00"}

  3. #13
    Sencha User
    Join Date
    Mar 2013
    Posts
    2
    Vote Rating
    0
      0  

    Default This was the only working answer that I found from documentation using version 4.2.1

    Code:
    Ext.Date.patterns = {
        ISO8601Long:"Y-m-d H:i:s",
        ISO8601Short:"Y-m-d",
        ShortDate: "n/j/Y",
        LongDate: "l, F d, Y",
        FullDateTime: "l, F d, Y g:i:s A",
        MonthDay: "F d",
        ShortTime: "g:i A",
        LongTime: "g:i:s A",
        SortableDateTime: "Y-m-d\\TH:i:s",
        UniversalSortableDateTime: "Y-m-d H:i:sO",
        YearMonth: "F, Y"
    };
    
    
    //allow max date as today
    Ext.override(Ext.form.DateField, {
        maxValue:new Date(),
        submitFormat:Ext.Date.patterns.ISO8601Short
    });

  4. #14
    Sencha Premium User alexander.urban's Avatar
    Join Date
    Nov 2013
    Posts
    314
    Answers
    9
    Vote Rating
    49
      1  

    Default

    @mcarballosam I would recommend against Ext.override.


    Ext.define('MyApp.override.DateField',{
    override:'Ext.form.DateField'


    is the new recommended way of overriding. Ext.override is deprecated and no longer part of newer ext versions.


    I would also recommend not to mess with the default formats of all date fields (this could have impact on derived fields, if such exist), but to use


    Ext.create('Ext.form.DateField',{
    maxValue:new Date(),
    submitFormat:Ext.Date.patterns.ISO8601Short
    });


    or, if it is embedded in a bigger (e.g. window/form) config


    {
    xtype:'datefield',
    maxValue:new Date(),
    submitFormat:Ext.Date.patterns.ISO8601Short
    }

  5. #15
    Sencha User
    Join Date
    Mar 2013
    Posts
    2
    Vote Rating
    0
      0  

    Default

    Alexander, thank you for the advice on the override method being deprecated.
    I am sorry I forgot to include on my post that I am using this as a global solution, because my intention is to override all date fields across the entire application on purpose, so I can achive the expected behaviour with that radical implementation.

  6. #16
    Sencha User
    Join Date
    Oct 2011
    Posts
    19
    Vote Rating
    0
      0  

    Default

    Quote Originally Posted by Zdeno View Post
    Code:
    submitFormat: 'Y-m-d H:i:s',
    submitValue : true
    works fine for me
    Hi,
    I am using this configuration in gridcolumn

    Code:
    {
        header : 'Date',
        name : 'deffecdate',
        xtype : 'datecolumn',
        editor : {
            xtype : 'datefield',
            submitFormat : 'Y-m-d'
        }
    }
    I am using a model, json store and sending the request with store.sync...
    The request that is send look like this
    [{"deffecdate":"2017-03-01T00:00:00"}]

    Why send '2017-03-01T00:00:00' instead of ''2017-03-01'?

    I create a breakpoint in getSubmitValue function and this function never is called when store.sync is called.

    Sorry if my english is bad...

  7. #17
    Sencha Premium User alexander.urban's Avatar
    Join Date
    Nov 2013
    Posts
    314
    Answers
    9
    Vote Rating
    49
      0  

    Default

    Quote Originally Posted by jconcept View Post
    I am using a model, json store and sending the request with store.sync...
    And there we have the problem.

    Why send '2017-03-01T00:00:00' instead of ''2017-03-01'?
    If you use a store to send, the submitFormat of the field is irrelevant - it is only used on form submit. This is not explicitly stated in the ExtJS docs.

    Instead, in the field definition you either have in your model or on the store, you want to make the field a field of type date, and set the dateFormat:

    http://docs.sencha.com/extjs/6.2.1/c...cfg-dateFormat

    Code sample:
    Code:
    fields:[{
        name:'StartDate',
        type:'date',
        dateFormat:'Y-m-d H:i:s'

  8. #18
    Sencha User
    Join Date
    Oct 2011
    Posts
    19
    Vote Rating
    0
      0  

    Default

    Quote Originally Posted by alexander.urban View Post
    Code sample:
    Code:
    fields:[{
        name:'StartDate',
        type:'date',
        dateFormat:'Y-m-d H:i:s'
    Is working.
    Thanks you very much...

  9. #19
    Sencha Premium User Nux's Avatar
    Join Date
    Feb 2016
    Location
    3city, Poland
    Posts
    31
    Vote Rating
    2
      0  

    Default

    I was not able to force formatting a date in record as a string after cell edit. Seems like a bug in ExtJS that is still a problem at least until ExtjS 6.2.1...

    Anyway I was able to make a workaround by using `editor` event on the grid.
    PHP Code:
    Ext.define('Myapp.view.settings.SomeSettingsGrid', {
        
    extend'Ext.grid.Panel',
        
    alias'widget.someSettingsgrid',
        
    store: {
            
    type'someSettingsstore'
        
    },
        
    plugins: {
            
    ptype'cellediting',
            
    clicksToEdit1
        
    },
        
    listeners : {
            
    edit : function(editore){
                var 
    record e.record;
                
    // force `submitFormat: 'Y-m-d'`
                
    var dateValue record.get('settingKey');
                if (
    typeof dateValue !== 'string') {
                    
    record.set('settingKey'Ext.Date.format(dateValue'Y-m-d'));
                }
            }
        },
        
    columns: {
            
    defaults: {
                
    flex2,
                
    sortablefalse,
                
    menuDisabledtrue
            
    },
            
    items: [
                {
                    
    text'Date',
                    
    xtype'datecolumn',
                    
    dataIndex'settingKey',
                    
    editor: {
                        
    xtype'datefield',
                        
    // Not working! Value is still formatted as `Date` and not as a ISO formatted date string.
                        
    submitFormat'Y-m-d',
                        
    allowBlankfalse
                    
    }
                },
                
    // ...
            
    ]
        }
    }); 
    See also this stackoverflow answer: https://stackoverflow.com/a/18585625/333296

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •