PDA

View Full Version : Problem getting correct date format for http post



nickweavers
1 Nov 2009, 12:43 PM
Hi, I am using an editable grid and am having trouble when I use a listener to send an updated date field back to the server to use in a MySQL update.

The cut down code looks like this:


store = new Ext.data.JsonStore({
url: 'employee.php',
baseParams: {
task: 'employee_records',
controller: '',
view: '',
format: ''
},
totalProperty:'totalCount',
root: 'rows',
idProperty: 'id_employee',
fields: [
...
{name: 'DateHired', type: 'date', dateFormat: 'Y-m-d', mapping: 'date_hired'},
...
]
});
var dateHiredRenderer = new Ext.util.Format.dateRenderer('d/m/Y');
var dateHiredEditor = new Ext.form.DateField({format: 'd/m/Y'});
var grid = new Ext.grid.EditorGridPanel({
title: 'Employees',
...
store: store,
columns: [{
header: 'Date Hired',
width: 80,
dataIndex: 'DateHired',
sortable: true,
renderer: dateHiredRenderer,
editor : dateHiredEditor
},
...
],
listeners: {
afteredit: function(e) {
var conn = new Ext.data.Connection();
conn.request({
url: 'employee.php',
params: {
task: 'update_employee_record',
id: e.record.id,
field: e.field,
value: e.value
},
success: function(resp, opt) {
e.commit();
},
failure: function(resp, opt) {
e.reject;
}
})
}
}
});
store.load({params:{start:0, limit:5}});
return grid;

The problem is that when the date field is sent back the the server it has the following format: Wed Oct 17 1900 00:00:00 GMT+0100 which causes mySQL to gripe.

How do I ensure that dates are sent back to the server in a MySQL compatible format (ie yyyy-mm-dd)?

TIA.

nickweavers
1 Nov 2009, 2:10 PM
Just found the solution posted in another thread which was answered by @jarlau



value : Ext.isDate(e.value) ? Ext.util.Format.date(e.value, 'd.m.Y') : e.value

Jaitsu
1 Nov 2009, 2:13 PM
I've noticed a few posts related to this, but what's wrong with server-side processing? It's far more efficient and you shouldn't trust client-side data to be valid... ever

nickweavers
1 Nov 2009, 3:21 PM
I've noticed a few posts related to this, but what's wrong with server-side processing? It's far more efficient and you shouldn't trust client-side data to be valid... ever

What's not to trust? It isn't data validation were talking about. It's just a matter of sending the data in the right format. And I don't really see what it has to do with efficiency either.