PDA

View Full Version : Ext.util.JSON.encodeDate question



bryanevil
19 Jul 2010, 10:34 PM
I have this at the top of my script to make my datetime output into MS JSON format at server POST:


Ext.util.JSON.encodeDate = function (d) {
return "\"" + d.format('M$') + "\"";
};


It work so far with my grid, until after I added a formpanel for select the date, and copy to my grid. From the grid, ext stop output the MS JSON format when POST.

But after that, if I re-select the data from the grid, that date output MS JSON format. Why? And how to fix this?


this is my ext form:



var OrderForm = new Ext.form.FormPanel({
id: 'OrderForm',
layout: 'form',
frame: true,
renderTo: Ext.getBody(),
width: 550,
labelWidth: 110,
autoHeight: true,
record: null,
items: [
{
layout: "column",
items: [{
columnWidth: .5,
layout: "form",
items: [new Ext.form.DateField({
fieldLabel: 'Shipment Date',
name: 'ShipmentDate', width: 120, allowBlank: false
})]
}, {
columnWidth: .5,
layout: "form",
items: [new Ext.form.DateField({
fieldLabel: 'Request Date',
name: 'DateOfRequest', width: 120, allowBlank: false
})]
}]
}

],
buttons: [ {
text: 'Create',
handler: function (btn, ev) {
if (!OrderForm.getForm().isValid()) {
return false;
}
OrderForm.fireEvent('create', OrderForm, OrderForm.getForm().getValues());
OrderForm.getForm().reset();
},
scope: this
}],
listeners: {
//copy to my grid
create: function (fpanel, data) {
var rec = new OrderGrid.store.recordType(data);
OrderGrid.store.insert(0, rec);
}
}
});


my grid's column:

[
....
{ header: 'Shipment Date', width: 100, sortable: true, editor: new Ext.form.DateField(), dataIndex: 'ShipmentDate' },
{ header: 'Request Date', width: 100, sortable: true, editor: new Ext.form.DateField(), dataIndex: 'DateOfRequest' }....
];

Animal
20 Jul 2010, 12:19 AM
Did you actually look at the POSTed JSON to check that it is valid?

What do you see when you do?

bryanevil
20 Jul 2010, 12:39 AM
Did you actually look at the POSTed JSON to check that it is valid?

What do you see when you do?

this is the Posted JSON:

{"CompanyId":178,"d":{"ShipmentDate":"07/14/2010","DateOfRequest":"07/15/2010"}}

if I re-select the date from the grid:

{"CompanyId":178,"d":{"ShipmentDate":"\/Date(1280246400000)\/","DateOfRequest":"\/Date(1279123200000)\/"}}

Condor
20 Jul 2010, 1:03 AM
BasicForm.getValues() will return the field values as Strings. You want BasicForm.getFieldValues() so you get Dates as values.