Results 1 to 4 of 4

Thread: Date format on submit

  1. #1

    Default Date format on submit

    Hi, I have a datefield in my form panel. I want to format the date in order to pass the mysql format to my php submit page. I'd like to not change the current format displayed for my datefield.

    Here's the code:

    Code:
    Ext.onReady(function() {
    
        Ext.QuickTips.init();
    
        var formPlan = new Ext.FormPanel({
                labelWidth: 75,
                frame: true,
                title: 'New Plan',
            waitMsgTarget: true,
            monitorValid: true,
                width: 350,
            defaults: {
                width: 210,
                msgTarget: 'side',
            },
            defaultType: 'textfield',
    
            items :[{
                fieldLabel: 'Name',
                name: 'name',
                allowBlank: false
            }, new Ext.form.DateField({
                fieldLabel: 'Start',
                name: 'date_start',
                format: 'F j, Y',
                allowBlank: false
            }), new Ext.form.DateField({
                fieldLabel: 'End',
                name: 'date_end',
                format: 'F j, Y',
                allowBlank: false
            }), new Ext.form.TextArea({
                fieldLabel: 'Description',
                name: 'description',
                allowBlank: true
            })
            ],
    
            buttons: [{
                text: 'New',
                formBind: true,
                handler: function() {
                    formPlan.form.submit({
                        url: 'ajax/plan.php',
                        method: 'POST',
                        params: {action: 'new'},
                        waitMsg:'Saving Data...',
                        success: function (form, action) {
                            Ext.MessageBox.alert('Message', 'Plan saved.');
                        },
                        failure: function(form, action) {
                            Ext.MessageBox.alert('Message', 'Save failed');
                        }
                    });
                }
                    },{
                        text: 'Cancel',
                handler: function() {
                    formPlan.form.reset();
                }
                }]
        });
    
        formPlan.render('plan');
    });

  2. #2
    Sencha User dlbjr's Avatar
    Join Date
    Oct 2007
    Location
    Cache, OK USA
    Posts
    281

    Default What I do

    Add the following function to your project
    Code:
    function getDateValue(obj,format) {
    var strReturn = '';
    try {
         strReturn = obj.getValue().format(format).trim();
    }
    catch (err) {
         strReturn = '';
    }
    return strReturn;
    } 
    Give your date fields and id value.
    Code:
    new Ext.form.DateField({
                id: 'date_start',
                fieldLabel: 'Start',
                name: 'date_start',
                format: 'F j, Y',
                allowBlank: false
    Then in the parameters of the form submit code add a parameter as such

    Code:
    formPlan.form.submit({
    url: 'ajax/plan.php',
    method: 'POST',
    params: { action: 'new',
          date_value1: getDateValue(Ext.get('date_start'),'Ymd')
    },
    waitMsg: 'Saving Data...',
    success: function(form, action) {
          Ext.MessageBox.alert('Message', 'Plan saved.');
    },
    failure: function(form, action) {
         Ext.MessageBox.alert('Message', 'Save failed');
    }
    });
    This allows me to set the dates dynamically to what ever I want
    dlbjr - David L. Bryant Jr.

    Owner of
    dlbjr Technology Consulting
    Web2 System Developer & Consultant
    Focused on C.I. - Six Sigma - Shingo - Lean Technologies
    [email protected]

    Owner of:
    Attractive Graphics - "custom screen printing"
    [email protected]

  3. #3

    Default

    nice! thank you!

  4. #4

Posting Permissions

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