PDA

View Full Version : Problem trapping json read errors on formpanel



murrah
30 Nov 2007, 6:19 PM
Hi.

I am building a complete example of using FormPanel and json to help me (and others) get their head around this.

ie Load data from server, allow data entry, submit back to server.

It all works properly except for one thing. For demo purposes I want to simulate the situation where the form load fails on the server side for some reason eg a database error.

To correctly load the data the following json works:


{ "success": true, "data":[
{"id":1, "firstname":"Jack", "lastname":"Slocum", "company":"Ext JS", "email":"[email protected]", "state":"OH", "dob":"04/15/2007"}
] }


So, what do you use to simulate a failure? I tried

{ "success": false }
and

{"success": false, "message": "Database not available"}
but that resulted in the "Loading" message to keep displaying and the script just seemed to keep going.

The error trapping on the form submit works fine:

{success: true} // if no errors on submitting, or
{success: false, errors:{firstname:"Must not be Jack!", company:"Must not be empty"} } // to simulate errors

Here is my load code:


fs.addButton('Load', function(){
fs.form.load({
url:'json-form-getjson.cfm',
waitMsg:'Loading',

success: function (result,request) {
Ext.MessageBox.alert('Message', 'Loaded OK');
},

failure: function (result,request) {
Ext.MessageBox.alert('Error', 'Load failed');
}
});
});


Thanks,
Murray

tryanDLS
30 Nov 2007, 8:46 PM
Is this with RC1? Seems to be working for me with something like:


fs.form.load({
url:'json-form.js', method:'GET', waitMsg:'Loading',
failure:function(form, action) {
alert('Form load failed with error: ' + action.result.msg);
}
});
and this response


{
success:false, msg:'Failed'
}

murrah
30 Nov 2007, 9:36 PM
Is this with RC1?

Yes, RC1.

The json is returning as (from Firebug console):

{success: false, msg: "Record 3 not found."}

The load function is now:


fs.addButton('Load', function(){

var idFld = getRecordID(); // Ask the user for a record number to find.
fs.form.load({

url:'json-form-getjson.cfm?recordid='+idFld,
waitMsg:'Loading',
success: function (o,result) {
Ext.MessageBox.alert('Message', 'Loaded OK');
},
failure: function (o,result) {
alert('Failed');
}
});
});


The success message comes up when a successful json is returned.
If the above "failure" json is returned the load doesnt finish - it just keeps displaying the wait message.

Thanks,
Murray

hendricd
1 Dec 2007, 6:14 AM
This always seems to create confusion.

The success/failure callbacks are HTTP transport success/fails.

You really need to also evaluate the forms' actioncomplete and actionfailed events. They are driven by your success: property.

tryanDLS
1 Dec 2007, 10:45 AM
The success/failure callbacks are are HTTP transport success/fails at the Ajax request level, but for form loading/submitting they are based on what's in the json data. This is basically the xml-form example converted to use JSON. If you flip the comments in the json-form.js file, you'll get the failure alert.



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>JSON Form</title>
<link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />
<script type="text/javascript" src="../../adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../../ext-all.js"></script>
<script type="text/javascript" src="states.js"></script>
<link rel="stylesheet" type="text/css" href="forms.css" />
<link rel="stylesheet" type="text/css" href="../examples.css" />
</head>
<body>
<script type="text/javascript" src="../examples.js"></script>
<script type="text/javascript">
Ext.onReady(function(){
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';

var fs = new Ext.FormPanel({
frame: true,
title:'JSON Form',
labelAlign: 'right',
labelWidth: 85,
width:340,
waitMsgTarget: true,
items: [
new Ext.form.FieldSet({
title: 'Contact Information',
defaultType: 'textfield',
items: [{
fieldLabel: 'First Name',
name: 'first',
width:190
}, {
fieldLabel: 'Last Name',
name: 'last',
width:190
}, {
fieldLabel: 'Company',
name: 'company',
width:190
}, {
fieldLabel: 'Email',
name: 'email',
vtype:'email',
width:190
},

new Ext.form.ComboBox({
fieldLabel: 'State',
hiddenName:'state',
store: new Ext.data.SimpleStore({
fields: ['abbr', 'state'],
data : Ext.exampledata.states // from states.js
}),
valueField:'abbr',
displayField:'state',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
emptyText:'Select a state...',
selectOnFocus:true,
width:190
}),

new Ext.form.DateField({
fieldLabel: 'Date of Birth',
name: 'dob',
width:190,
allowBlank:false
})
]
})
]
});

fs.addButton('Load', function(){
fs.form.load({
url:'json-form.js', method:'GET', waitMsg:'Loading',
failure:function(form, action) {
alert('Form load failed with error: ' + action.result.msg);
}
});
});

var submit = fs.addButton({
text: 'Submit',
disabled:true,
handler: function(){
fs.form.submit({url:'json-errors.js', method:'GET', waitMsg:'Saving Data...'});
}
});

fs.render('form-ct');

fs.on({
actioncomplete: function(form, action){
if(action.type == 'load'){
submit.enable();
}
}
});
});
</script>
<h1>Loading/Saving a Dynamic Form using JSON</h1>
<p>
This is a very simple example of using JSON for load and submit of data with an Ext dynamic form.
</p>
<p>
After loading the form, you will be able to hit submit. The submit action will make a post to the server,
and the <a href="json-errors.js">dummy JSON file</a> on the server with test server-side validation failure messages will be sent back.
Those messages will be applied to the appropriate fields in the form.
</p>

<div id="form-ct"></div>

</body>
</html>


json-form.js


// test for valid
{
success:true,
data:{first:'Jack', last:'Slocum', company:'Ext JS', email:'[email protected]', state:'OH', dob:'04/15/2007'}
}

// test for invalid
/*
{
success:false, msg:'Failed'
}
*/


json-errors.js


{
success:false,
errors:{first:'First name is required', dob:'Missing DOB'}
}

murrah
2 Dec 2007, 11:40 AM
Thanks for your help.

I have tested your sample and that works fine. However using the same logic and json format in my code still causes the problem when the success is false even though the returned json is correct.

Using Firebug, the code seems to be "hanging" at line 11408 in ext-all-debug.js. The debugger shows the correct json in variable "o" as in:


11408: var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;

Object success=false msg=Record 3 not found.



So, I think the problem is elsewhere. I have included the full js file because I suspect that the problem is my reader. The docs say that when using json you dont need to specify your own reader. Lots of the examples that I have been using to work out how to do the form load/submit process specify a reader. Indeed, if I remove the reader from my code the form data doesnt show up in the form fields even though the script seems to work without errors.

So, maybe the problem is my reader? And if you dont need to specify one, what do I need to do instead?

Thanks again for your help. Once this is working I will post the complete working example for others to use to save all this support.

To show correct loading use record 1 or 2 when asked. To show the problem, specify 3 for the record number.



/*
* Ext JS Library 2.0 Beta 1
* Copyright(c) 2006-2007, Ext JS, LLC.
* [email protected]
*
* http://extjs.com/license
*/

Ext.onReady(function(){

Ext.QuickTips.init();

// turn on validation errors beside the field globally
Ext.form.Field.prototype.msgTarget = 'side';

recordObj = Ext.data.Record.create([
{name: 'id'},
{name: 'firstname'},
{name: 'lastname'},
{name: 'company'},
{name: 'email'},
{name: 'state'},
{name: 'dob', type:'date', dateFormat:'m/d/Y'},
]);

myReader = new Ext.data.JsonReader({
root: 'data',
id: 'id'
}, recordObj);

var fs = new Ext.FormPanel({
frame: true,
title:'JSON Form',
labelAlign: 'right',
labelWidth: 85,
width:340,
waitMsgTarget: true,
reader : myReader,

items: [
new Ext.form.FieldSet({
title: 'Contact Information',
defaultType: 'textfield',
items: [
// An example of a NumberField to gain client side validation
new Ext.form.NumberField({
fieldLabel: 'Record ID',
allowBlank:false,
blankText:'You must enter a number',
allowDecimals:false,
decimalPrecision:0,
maxValue:10,
minValue:1,
value:1,
width:40,
name: 'id'
}),

{
fieldLabel: 'First Name',
name: 'firstname',
width:190
}, {
fieldLabel: 'Last Name',
name: 'lastname',
width:190
}, {
fieldLabel: 'Company',
name: 'company',
width:190
}, {
fieldLabel: 'Email',
name: 'email',
vtype:'email', // Validate as an email field
width:190
},

new Ext.form.ComboBox({
fieldLabel: 'State',
hiddenName:'state',
store: new Ext.data.SimpleStore({
fields: ['abbr', 'state'],
data : Ext.exampledata.states // from states.js
}),
valueField:'abbr',
displayField:'state',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
emptyText:'Select a state...',
selectOnFocus:true,
width:190
}),

new Ext.form.DateField({
fieldLabel: 'Date of Birth',
name: 'dob',
width:190,
allowBlank:false
})
]
})
]
});

function getRecordID() {
// Quick and dirty way of getting a record number from the user
var recid = prompt("Please enter the ID of a record. A value of 1 or 2 will return a record.","1");
if (!recid) recid = 1;
return recid;
}

// simple button add
fs.addButton('Load', function(){

var idFld = getRecordID(); // Ask the user for a record number to find.
fs.form.load({

url:'json-form-getjson.cfm?recordid='+idFld,
waitMsg:'Loading',
success: function (o,result) {
Ext.MessageBox.alert('Message', 'Loaded OK');
},
failure:function(form, action) {
alert('Form load failed with error: ' + action.result.msg);
}

});
});

// Define the Submit button and the action required. This will be enabled if the Load is successful.
var submit = fs.addButton({
text: 'Submit',
disabled:true,
handler: function(){
fs.form.submit(
{url:'json-form-submit.cfm',
waitMsg:'Saving Data...',
success: function (result,request) {
Ext.MessageBox.alert('Message', 'Saved OK');
},
failure: function (result,request) {
Ext.MessageBox.alert('Error', 'Save failed');
}
});
}
});

fs.render('form-ct');

fs.on({
actioncomplete: function(form, action){
if(action.type == 'load'){
submit.enable();
}
}
});

});




json-form-getjson.cfm:


<cfsetting showdebugoutput="no"> <!--- To supress any debugging code that will upset the json return --->

<cfparam name="url.recordid" default="1"> <!--- If no url parm, set one --->

<cfif url.recordID eq 1>
<cfset result = '{"success": true, "data":[{"id":1, "firstname":"Jack","lastname":"Slocum","company":"Ext JS","email":"[email protected]","state":"OH","dob":"04/15/2007"}]}'>
<cfelseif url.recordID eq 2>
<cfset result = '{"success": true, "data":[{"id":2, "firstname":"Murray","lastname":"Hopkins","company":"Murrah","email":"[email protected]","state":"NSW","dob":"07/26/2000"}]}'>
<cfelse>
<cfset result = '{success: false, msg: "Record #url.recordID# not found."}'>
</cfif>

<!--- There MUST NOT BE any spaces between the end of the cfcontent tag and the cfoutput tag.
The RESET gets rid of all preceeding white space. --->
<CFCONTENT
TYPE="text/plain"
RESET="Yes"><CFOUTPUT>#result#</CFOUTPUT>

tryanDLS
2 Dec 2007, 11:53 AM
What you're doing is not supported out of the box by the Form load process. The load process doesn't expect to handle more than 1 record. That's why there's no JsonReader and the response data is not in array, as opposed to how you would do it you were loading a store. You don't need a reader for Json - it will just match property names in your response data to the field names in the form. The xml version of that example uses a reader b/c you need a way to parse the xml into a JS object.

hendricd
2 Dec 2007, 12:22 PM
As no reader you have defined (or defaults) supports your 'msg' response member, couldn't you can deal with it on actionfailed since success = false ?:




form.on('actionfailed', function(form,action){
var result = Ext.decode(action.response.responseText);
if(action.type == 'load' && result && result.msg) {


}

});

murrah
2 Dec 2007, 12:59 PM
Thanks to both of you. I will do some more experimenting.

The scenario is this:

I have a grid that displays 2 fields from a db table record that has 8 fields. When the user double clicks the grid row the form opens in a window that displays all 8 fields populated from the database via json. The user edits the data, saves the changes via the submit to server then the grid row is refreshed.

What I cant get my head around (and was trying to modify the provided examples) is how to pass the required recordID on the form so the server-side load provides the right record from the database to the form.

The sample code was my experiment on that aspect - leaving aside the question of how I get the recordID from the grid row but I am assuming that is simple enough.

Any pointers you can give me will be gratefully accepted.

Thanks again,
Murray

hendricd
2 Dec 2007, 1:39 PM
grid.getSelectionModel().on('rowselect',function(sm,index,record){
fs.form.baseParams || (fs.form.baseParams = {});
Ext.apply(fs.form.baseParams,{recordId: record.data.id });

});


and, remove it from your url string. ;)

That way either action (load/submit) always gets the currently selected grid rows' id....

murrah
2 Dec 2007, 9:15 PM
Thanks Doug,

I will give it a try.

Cheers,
Murray

murrah
3 Dec 2007, 4:21 AM
Again, thanks for your help.

I now have the loading and submitting working as I want. I still have one question to resolve before I post the complete working example for others. This is in regards to the difference between the load failure function and the on.actionfailed method.

Apart from alerting the user when the load json returns with success=false, I wanted to see what would happen if the page on the server that returns the json could not be found (thus simulating some kind of server connection issue). It seems that I can trap both these error conditions using the following code without specifying an on.actionfailed method at all:


fs.addButton('Load', function(){
fs.form.load({
url:'json-form-getjson.cfm', // Coldfusion
//url:'json-form-getjson.php', // PHP
method:'GET',
waitMsg:'Loading',

success:function(form, action) { // Optional function
Ext.MessageBox.alert('Message', 'Loaded OK');
},

failure:function(form, action) {
if (action.failureType == "connect") {
Ext.MessageBox.alert('Error', 'Form load failed. Could not connect to server.');
} else {
if (action.result && action.result.msg){
Ext.MessageBox.alert('Error', 'Form load failed with error: ' + action.result.msg);
} else {
Ext.MessageBox.alert('Error', 'Form load failed with unknown error');
}

}
}
});
});


Now, I understand that the on.actionfailed method is to trap http level errors but if they can be trapped by the failure function is there another purpose for the on.actionfailed method? What is best practice here for robust error trapping on form loads (and submits, for that matter)? I want to include that in the example I am building.

Thanks,
Murray

hendricd
3 Dec 2007, 6:10 AM
As in most AJax related features, you have a choice between a callback and/or an event. They both get the same parameters. Matter of preference it would seem.

IMO: If I were linking another Components 'behavior' (eg. logging/list operation) to the result of a Form operation, I would probably choose the listener over the callback.

Nice that you have a choice tho =D>

murrah
3 Dec 2007, 11:44 AM
Thanks.

I did some more testing on the load error trapping. I found that you actually need to use both functions:

Actually, this is all wrong! Please ignore this post. See the updated post below. (Murrah)



/*
A note re error trapping.
There are 2 ways to trap load errors - the on.actionfailed and the load.failure.

The load.failure and load.success functions are fired based upon the success
field passed in the json that comes from the server.

The various possible error conditions I can think of are trapped as follows:
1. The server script (json-form-getjson.cfm/php in this case) is not found:
load.failure is fired, on.actionfailed is not fired
(Presumably other server errors that resulted in no return would result
in the same error conditions)

2. The server script (json-form-getjson.cfm/php in this case) is found and the
server script itself trapped an error eg the record was not found in the database table.
Consequently you return success:false in the json.
load.failure is fired, on.actionfailed is not fired

3. json success field is missing altogether (or misspelt):
load.failure not fired, on.actionfailed is fired

4. json success field is not true or false eg a typo - success:tru :
neither gets fired, the load function never returns and the wait message keeps displaying.
(Bug in Ext???)


So, the code below takes the following approach:
Catch errors 1,2 and 4 in the load.failure function. Catch error 3 in the on.actionfailed listener.

*/

fs.addButton('Load', function(){
fs.form.load({
url:'json-form-getjson.cfm', // Coldfusion
//url:'json-form-getjson.php', // PHP
method:'GET',
waitMsg:'Loading',

success:function(form, action) { // Optional function
Ext.MessageBox.alert('Message', 'Loaded OK');
},

failure:function(form, action) {
if (action.failureType == "connect") { // error type 1. see above
Ext.MessageBox.alert('failure error', 'Form load failed. Could not connect to server.');
} else {
if (action.result && action.result.msg){ // error type 2. see above
Ext.MessageBox.alert('failure error', 'Form load failed with error: ' + action.result.msg);
} else { // catch all others
Ext.MessageBox.alert('failure error', 'Form load failed with unknown error');
}
}
}
});
});

// Define the Submit button and the action required. This will be enabled if the Load is successful.
var submit = fs.addButton({
text: 'Submit',
disabled:true,
handler: function(){
fs.form.submit({
url:'json-form-submit.cfm', // Coldfusion
//url:'json-form-submit.php', // PHP
waitMsg:'Saving Data...',

success: function (result,request) {
Ext.MessageBox.alert('Message', 'Saved OK');
},
failure: function (result,request) {
Ext.MessageBox.alert('Error', 'Save failed');
}
});
}
});

fs.render('form-ct');

fs.on({
actioncomplete: function(form, action){
//Ext.MessageBox.alert('actioncomplete', 'All good');
if(action.type == 'load'){
submit.enable();
}
},
actionfailed: function(form,action){
var result = Ext.decode(action.response.responseText);
if(action.type == 'load' && result && result.msg) {// probably wont happen?
Ext.MessageBox.alert('actionfailed Error', 'Form load failed with error: ' + action.result.msg);
} else {// error type 3 and catch all. see above
Ext.MessageBox.alert('actionfailed Error', 'Form load failed with unknown error (possibly missing the "success" field in the json). Failure type='+action.failureType);
}
}
});


There may still be more to this but it is getting more robust now.

Cheers,
Murray

hendricd
3 Dec 2007, 11:58 AM
Nice test summary. =D>

IMHO: the actioncomplete/failed events should always fire regardless of the outcome. (after the bugs are worked out) ;)

murrah
3 Dec 2007, 12:43 PM
Thanks.

I will test the possible submit failure conditions and error trapping later today. I think I am getting close to finalising this example! :D

Murray

murrah
5 Dec 2007, 3:34 AM
Ok, after much testing and experimenting, here is what I have discovered about error handling of form load and submit with json. The following is just the load and submit sections. When I have finished working up the formPanel example that this comes from I will post that as a separate thread and put a link from this thread.

If anyone has anything to add or correct, please do so! I am fairly new to Ext so I may have missed something.



/***********************************
There are a couple of functions you can use to check the success or failure of
form loads and submits.
* formPanel.onactioncomplete and formPanel.onactionfailed
* formPanel.form.load.success, formPanel.form.load.failure
* formPanel.form.submit.success, formPanel.form.submit.failure
See how these are implemented below.

All these functions are optional but for robust error checking you should use them and
take appropriate action. The following should help you understand what to do.

FORM LOADING:

Successful load : both the formPanel.form.load.success and the formPanel.onactioncomplete fire

Unsuccessful load:
There are 2 ways to trap load errors - the on.actionfailed and the load.failure.
In all cases except 4 (below) both the load.failure and on.actionfailed are fired.
You have various options for trapping and reporting the folowing errors.

The various possible error conditions I can think of are trapped as follows:
1. The server script (json-form-getjson.cfm/php in this case) is not found:
load.failure is fired, on.actionfailed is fired
(Presumably other server errors that resulted in no return would result
in the same error conditions)

2. The server script (json-form-getjson.cfm/php in this case) is found and the
server script itself trapped an error eg the record was not found in the database table.
Consequently you return success:false in the json.
load.failure is fired, on.actionfailed is fired

3. json success field is missing altogether (or misspelt):
load.failure fired, on.actionfailed is fired

4. json success field is neither true or false eg a typo - success:tru :
neither gets fired, the load function never returns and the wait message keeps displaying.
(Bug in Ext???)

5. json is an EMPTY string.
load.failure is fired, on.actionfailed is fired
If the string is just spaces, see result 4 above.


FORM SUBMIT:
Successful submit : both the formPanel.form.submit.success and the formPanel.onactioncomplete fire

Unsuccessful submit:
The various possible error conditions I can think of are trapped as follows:
1. The server script (json-form-submit.cfm/php in this case) is not found:
submit.failure is fired, on.actionfailed is fired
(Presumably other server errors that resulted in no return would result
in the same error conditions)

2. The server script (json-form-submit.cfm/php in this case) is found and the
server script itself trapped an error eg saving would create a duplicate record
in the database table, or updating a non existing record, etc.
Consequently you return success:false in the json.

submit.failure is fired, on.actionfailed is fired
3. json success field is missing altogether (or misspelt):
submit.failure is fired, on.actionfailed is fired

4. json success field is neither true or false eg a typo - success:tru :
neither gets fired, the submit function never returns and the wait message keeps displaying.
(Bug in Ext???)

5. json is an EMPTY string. Only the on.actioncomplete fires,
neither submit.failure is fired nor on.actionfailed is fired.
This also seems like a bug, but maybe there is some reason for it.
If the string is just spaces, see result 4 above.

So, to sum up for both load and submit, whenever there is some kind of error (apart from the type
listed at point 4 above), both the failure function AND the actionfailed function fire.
It then becomes a question of which function you should use to trap the errors (and then not
declaring the other one so that only one of the 2 functions fire).
Similarly, if you need to take action based upon a successful load or submit, declare either the success or actioncompleted
function.

So, the code below takes the approach that since the actionfailed function is used by both
load and submit it makes sense (IMO) to locate all the error checking there. There may be other
reasons that I am not aware of so dont take this as gospel. The one exception is where the json contains
an empty string on a submit and Ext doesnt raise an error. In that case you need the check in the actioncomplete
to pick that up.
*******************************************/

fs.addButton('Load', function(){
fs.form.load({
url:'json-form-getjson.cfm', // Coldfusion
//url:'json-form-getjson.php', // PHP
method:'GET',
waitMsg:'Loading'

/* Alternatively, instead of using actionfailed / complete (below) you could use these functions:
,
success:function(form, action) { // Optional function
Ext.MessageBox.alert('Message', 'Loaded OK');
},

failure:function(form, action) {
Ext.MessageBox.alert('Message', 'Load failed');
}
*/
});
});

// Define the Submit button and the action required. This will be enabled if the Load is successful.
var submit = fs.addButton({
text: 'Submit',
disabled:true,
handler: function(){
fs.form.submit({
url:'json-form-submit.cfm', // Coldfusion
//url:'json-form-submit.php', // PHP
waitMsg:'Saving Data...'

/* Alternatively, instead of using actionfailed / complete (below) you could use these functions:
,

success: function (form, action) {
Ext.MessageBox.alert('Message', 'Saved OK');
},
failure:function(form, action) {
Ext.MessageBox.alert('Message', 'Save failed');
}
*/
});
}
});

fs.render('form-ct');

fs.on({
actioncomplete: function(form, action){

// Only enable the submit button if the load worked
if(action.type == 'load'){
submit.enable();
Ext.MessageBox.alert('fs.actioncomplete', 'All OK.'); // Optional. Just for testing
}

if(action.type == 'submit'){
// If the responseText is a null string, Ext doesnt raise an error so trap it here
// as an error because it should be some json.
if(action.response.responseText == '') {
Ext.MessageBox.alert('fs.actioncomplete error', 'Form submit returned an empty string instead of json');
} else Ext.MessageBox.alert('fs.actioncomplete', 'All OK.'); // Optional. Just for testing
}
},
// The following code could be rationalised but I did it this way to make it easier
// to follow and for you to test it yourself.
// NOTE: the line var result = Ext.decode(action.response.responseText); must be
// called AFTER you have made sure there wasnt a failureType == "connect" or you
// will probably get a JS error in the Ext library.

actionfailed: function(form,action){
//alert('actionfailed');
if(action.type == 'load') { // Handle the LOAD errors
if (action.failureType == "connect") {
Ext.MessageBox.alert('fs.actionfailed error', 'Form load failed. Could not connect to server.');
} else {
if (action.response.responseText != '') {
var result = Ext.decode(action.response.responseText);
if(result && result.msg) {
Ext.MessageBox.alert('fs.actionfailed error', 'Form load failed with error: ' + action.result.msg);
} else {
Ext.MessageBox.alert('fs.actionfailed error', 'Form load failed with unknown error (possibly missing the "success" field in the json). Action type='+action.type+', failure type='+action.failureType);
}
} else {
Ext.MessageBox.alert('fs.actionfailed error', 'Form load returned an empty string instead of json');
}
}
}

if(action.type == 'submit') { // Handle the SUBMIT errors

if (action.failureType == "connect") {
Ext.MessageBox.alert('fs.actionfailed error', 'Form submit failed. Could not connect to server.');
} else
if (action.failureType == "server") {
// These arent "errors" as such, they are validation issues trapped by the server script and passed back for the user to correct
} else {
var result = Ext.decode(action.response.responseText);
if(result && result.msg) {
Ext.MessageBox.alert('fs.actionfailed error', 'Form submit failed with error: ' + action.result.msg);
} else {
Ext.MessageBox.alert('actionfailed Error', 'Form submit returned unknown error. Action type='+action.type+', failure type='+action.failureType);
}
}
}

} // end actionfailed listener
}); // end fs.on


Thanks to those who have helped me work this out.
Murray

murrah
6 Dec 2007, 12:51 PM
OK. Here is the link to the complete working example: http://extjs.com/forum/showthread.php?p=95977

Murray