Ext JS - Learning Center

Manual:Forms:Result Format

From Learn About the Ext JavaScript Library

Jump to: navigation, search

Ext.form.BasicForm and Ext.form.Form actions expect to receive certain parameters in the server response.

Contents

Load Action

JSON

The simplest JSON result if you do not use a JsonReader should look like this:

{
	"success": true,
	"data": {
		"field_id_1": "Field 1 Value",
		"field_id_2": "Field 2 Value"
	}
}

Submit Action

JSON

If a JsonReader is not being used, the server response to a form submit should be in either of the following formats:

{
	"success": false,
	"errors": {
		"field_id_1": "Field 1 Error Message",
		"field_id_2": "Field 2 Error Message"
	}
}

or

{
	"success": false,
	"errors": [
		{ "id": "field_id_1", "msg": "Field 1 Error Message" },
		{ "id": "field_id_2", "msg": "Field 2 Error Message" }
	]
}

"success" is a boolean value.

true will trigger the Form's "actioncomplete" event and the "success" callback option from the Form's submit call.

false will trigger the Form's "actionfailed" event and the "failure" callback option from the Form's submit call.

If you specify an "errors" array, Ext will mark the passed fields as invalid and the error message is displayed. The way the message is displayed depends on the msgTarget config property of the Ext.form.Field (or derived class). If you want the tooltip to show your error, be sure to have the QuickTips enabled:

Ext.QuickTips.init();
Ext.QuickTips.enable();

XML

<response success="false">
 <errors>
  <field>
   <id>first</id>
    <msg>Invalid name. <br /><i>This is a test validation message from the server </i>   </msg>
   </field>
   <field>
    <id>dob</id>
    <msg>Invalid Date of Birth. <br /><i>This is a test validation message from the server</i></msg>
   </field>
 </errors>
</response>
  • This page was last modified 11:54, 14 October 2007.
  • This page has been accessed 10,914 times.