PDA

View Full Version : Can't update my database from my formPanel



lpastor
24 Aug 2009, 8:50 AM
Hello,

When I click on my update button, I can see the MessageBox, but my database isn't updated.

There isn't Firbug error message... and there isn't ajax submit too !

This is my formpanel :


var gridForm = new Ext.FormPanel({
frame: true,
labelAlign: 'left',
layout: 'column',
items: [{
xtype: 'fieldset',
labelWidth: 90,
defaults: {width: 140, border:false},
defaultType: 'textfield',
autoHeight: true,
border: false,
listeners: { // Pour charger des données en provenance d'un serveur distant
afterlayout: function(g){
store.load({
callback: function(){
var idx = store.find('organisation_contact', 'INRIA');
gridForm.getForm().loadRecord(store.getAt(idx));
}
});
},
single: true
},
items: [
{fieldLabel: 'Nom Prénom', name:'nom_contact', width:300, allowBlank: false},
{fieldLabel: 'Organisation', name:'organisation_contact', width:300, allowBlank: true}
]
}],
buttons:[{
text: 'Update',
iconCls: 'icon-save',
handler: function(btn, ev) {
gridForm.getForm().updateRecord(this.record);
Ext.MessageBox.alert('UPDATE','');
},
scope: this
}]
});And my datastore script :


var proxy = new Ext.data.HttpProxy({
//url: 'app.php/users'
url: 'Mysql_Call.php?table=contact&idkey=id_contact',
method: 'POST'
});

//Typical JsonReader. Notice additional meta-data params for defining the core attributes of your json-response
var reader = new Ext.data.JsonReader({
totalProperty: 'total',
successProperty: 'success',
idProperty: 'id_contact',
root: 'data'
}, [
{name: 'id_contact'},
{name: 'nom_contact', sortDir: 'ASC', sortType: 'asUCString', allowBlank: false},
{name: 'organisation_contact'}
]);

var messagefield = 'nom_contact';

// The new DataWriter component.
var writer = new Ext.data.JsonWriter();

// Typical Store collecting the Proxy, Reader and Writer together.
var store = new Ext.data.Store({
id: 'id_contact',
proxy: proxy,
reader: reader,
writer: writer,
sortInfo:{field: 'nom_contact', direction: "ASC"},
listeners: {
write : function(store, action, result, response, rs) {}
}
});

httpdotcom
24 Aug 2009, 10:45 AM
formPanel.updateRecord() updates the passed record, but it doesn't submit the information to the backend. you will have to write that on your own (as either a separate AJAX call, or some store.update listener-based system)

lpastor
24 Aug 2009, 12:15 PM
Thank you httpdotcom for your reply,

I thought initially that was a listening work :


var store = new Ext.data.Store({
id: 'id_contact',
proxy: proxy,
reader: reader,
writer: writer,
sortInfo:{field: 'nom_contact', direction: "ASC"},
listeners: {
write : function(store, action, result, response, rs) {}
}
});

Know I listened you, I add a listener and I modified my script like this:


var gridForm = new Ext.FormPanel({
frame: true,
loadMask: true,
labelAlign: 'left',
layout: 'column',
items: [{
xtype: 'fieldset',
labelWidth: 90,
defaults: {width: 140, border:false},
defaultType: 'textfield',
autoHeight: true,
border: false,
listeners: {
afterlayout: function(g){
store.load({
callback: function(){
var idx = store.find('organisation_contact', 'INRIA');
gridForm.getForm().loadRecord(store.getAt(idx));
}
});
},
single: true,
update: function(fpanel, data) {
var rec = new store.recordType(data);
store.update(rec);
Ext.MessageBox.alert('UPDATE','');
}
},
items: [
{fieldLabel: 'Nom Prénom', name:'nom_contact', width:300, allowBlank: false},
{fieldLabel: 'Organisation', name:'organisation_contact', width:300, allowBlank: true}
]
}],
buttons:[{
text: 'Save',
iconCls: 'icon-save',
handler: function(btn, ev) {
//gridForm.getForm().updateRecord(this.record);
gridForm.fireEvent('update', this, gridForm.getForm().getValues());
},
scope: this
}]
});

It's not good my messageBox don't display too...:((

jarlau
24 Aug 2009, 5:43 PM
why not just use getForm().submit()?

http://extjs.com/deploy/dev/docs/?class=Ext.form.BasicForm&member=submit

lpastor
24 Aug 2009, 11:42 PM
Thanks Jarlau,

If there is an example to how implemente that ?

My json script came from the datawriter example, and I tried to studie that... With a lot of turn around.

Laurent

jarlau
24 Aug 2009, 11:59 PM
You don't have to use writer for Form. The API (http://extjs.com/deploy/dev/docs/?class=Ext.form.BasicForm&member=submit) has an example already. (did you know you can expand the doc to see the details of function?)