Question

I have Json data which is retrieving from database by sending an Ajax request.

{'tourData':[{ 'code' : '6', 'ref' : '22/01/2014 09:08:54-Route 2', 'vehicle' : 'GY-122-120', 'fromDate' : '2014-01-22 00:00:00', 'toDate' : '2014-01-22 00:00:00', 'tourAssign' : 'Saman', 'driver' : 'Kamal Subhasingha', 'assistant' : 'Sampath Jayaweera', 'porter1' : 'Namal Witharana', 'porter2' : 'Yohan', 'porter3' : 'Ahan Liyanage' } ]}

I try to set 'fromDate' as the value of a date field.

new Ext.form.DateField({
        id : 'fromDateCombo',
        fieldLabel : 'From Date',
        allowBlank : false,
        width : 140,
        name : 'fromDate',
        emptyText : 'From Date',
        hideLabel : true,
        format: 'd/m/Y',
        style : 'marginleft:10px',
        disabled : true,
        listeners : {
            select : function() {
                if (Ext.getCmp('toDateCombo').getValue()< this.getValue()) {
                    Ext.Msg.show({
                          title: 'Error',
                          msg: 'From Date should be less than or equal To Date' ,
                          buttons: Ext.MessageBox.OK,
                          icon: Ext.MessageBox.ERROR
                    });
                    this.setValue(sysDate);
                } 
            }, render: function(c) {
                new Ext.ToolTip({
                    target: c.getEl(),
                    html: 'From Date'
                });
            }

        }
    });

I've tried this.

var jsonData = Ext.util.JSON.decode(response.responseText);  
                            console.log(jsonData);
                            if (jsonData.tourData.length > 0) {

                                Ext.getCmp('fromDateCombo').setValue(Date.parseDate(String(jsonData.tourData[0].fromDate), 'd/m/Y'));

                            }

But it doesn't set the date and doesn't print any error message in my firebug console.

What's wrong with my codes and how can I fix it ?

Kind Regards

Was it helpful?

Solution

var fromDate = jsonData.tourData[0].fromDate;
console.log(fromDate); // it should not be undefined

var value = Date.parseDate(fromDate, "Y-m-d H:i:s");
Ext.getCmp('fromDateCombo').setValue(value);

OTHER TIPS

use

Date.parseDate(jsonData.tourData[0].fromDate, "Y-m-d g:i:s")

see working example here http://jsfiddle.net/vinodgubbala/82989/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top