PDA

View Full Version : Form submit doesn't callback success



reynardmh
10 Jun 2011, 12:12 PM
So I was trying to figure out why my FormPanel does not execute the success callback.
here is a quick example:



f = new Ext.form.FormPanel({
url: 'server/script'
items: [
{
xtype: 'textfield',
name : 'name',
label: 'name'
},
],
});

f.submit({
success: function() {
console.log('success'); // this doesnt get called
},
failure: function() {
console.log('failure'); // this gets called
}
});


I have the server script return text in json format. After some hair pulling and looking at the source code for FormPanel in sencha-touch-debug.js:26579. I see this


response = Ext.decode(responseText);
success = !!response.success;

Why does it look for success from the responseText? This means that the server side script needs to always send the response in this format


{
success: true,
responseData: [...]
}

Can't we use HTTP status for success or failure?

bclinton
11 Jun 2011, 10:04 PM
If you read the comments in FormPanel.submit in the API docs, it says:


success : Function
The callback that will be invoked after a successful response. A response is successful if a response is received from the server and is a JSON object where the success property is set to true, {"success": true}

It will probably be easiest to structure your server responses with the success property, but of course you could always override the submit method of FormPanel and put your own test in there.

reynardmh
12 Jun 2011, 1:45 PM
thanks for pointing that out, I guess it was my fault for not reading the documentation :( but it's kinda strange implementation.