4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-form-action-Submit'>/**
19 </span> * @class Ext.form.action.Submit
20 * @extends Ext.form.action.Action
21 * <p>A class which handles submission of data from {@link Ext.form.Basic Form}s
22 * and processes the returned response.</p>
23 * <p>Instances of this class are only created by a {@link Ext.form.Basic Form} when
24 * {@link Ext.form.Basic#submit submit}ting.</p>
25 * <p><u><b>Response Packet Criteria</b></u></p>
26 * <p>A response packet may contain:
27 * <div class="mdetail-params"><ul>
28 * <li><b><code>success</code></b> property : Boolean
29 * <div class="sub-desc">The <code>success</code> property is required.</div></li>
30 * <li><b><code>errors</code></b> property : Object
31 * <div class="sub-desc"><div class="sub-desc">The <code>errors</code> property,
32 * which is optional, contains error messages for invalid fields.</div></li>
33 * </ul></div>
34 * <p><u><b>JSON Packets</b></u></p>
35 * <p>By default, response packets are assumed to be JSON, so a typical response
36 * packet may look like this:</p><pre><code>
40 clientCode: "Client not found",
41 portOfLoading: "This field must not be null"
43 }</code></pre>
44 * <p>Other data may be placed into the response for processing by the {@link Ext.form.Basic}'s callback
45 * or event handler methods. The object decoded from this JSON is available in the
46 * {@link Ext.form.action.Action#result result} property.</p>
47 * <p>Alternatively, if an {@link Ext.form.Basic#errorReader errorReader} is specified as an {@link Ext.data.reader.Xml XmlReader}:</p><pre><code>
48 errorReader: new Ext.data.reader.Xml({
55 </code></pre>
56 * <p>then the results may be sent back in XML format:</p><pre><code>
57 &lt;?xml version="1.0" encoding="UTF-8"?&gt;
58 &lt;message success="false"&gt;
59 &lt;errors&gt;
61 &lt;id&gt;clientCode&lt;/id&gt;
62 &lt;msg&gt;&lt;![CDATA[Code not found. &lt;br /&gt;&lt;i&gt;This is a test validation message from the server &lt;/i&gt;]]&gt;&lt;/msg&gt;
63 &lt;/field&gt;
65 &lt;id&gt;portOfLoading&lt;/id&gt;
66 &lt;msg&gt;&lt;![CDATA[Port not found. &lt;br /&gt;&lt;i&gt;This is a test validation message from the server &lt;/i&gt;]]&gt;&lt;/msg&gt;
67 &lt;/field&gt;
68 &lt;/errors&gt;
69 &lt;/message&gt;
70 </code></pre>
71 * <p>Other elements may be placed into the response XML for processing by the {@link Ext.form.Basic}'s callback
72 * or event handler methods. The XML document is available in the {@link Ext.form.Basic#errorReader errorReader}'s
73 * {@link Ext.data.reader.Xml#xmlData xmlData} property.</p>
75 Ext.define('Ext.form.action.Submit', {
76 extend:'Ext.form.action.Action',
77 alternateClassName: 'Ext.form.Action.Submit',
78 alias: 'formaction.submit',
82 <span id='Ext-form-action-Submit-cfg-clientValidation'> /**
83 </span> * @cfg {Boolean} clientValidation Determines whether a Form's fields are validated
84 * in a final call to {@link Ext.form.Basic#isValid isValid} prior to submission.
85 * Pass <tt>false</tt> in the Form's submit options to prevent this. Defaults to true.
91 if (this.clientValidation === false || form.isValid()) {
94 // client validation failed
95 this.failureType = Ext.form.action.Action.CLIENT_INVALID;
96 form.afterAction(this, false);
100 <span id='Ext-form-action-Submit-method-doSubmit'> /**
102 * Perform the submit of the form data.
104 doSubmit: function() {
106 ajaxOptions = Ext.apply(this.createCallback(), {
108 method: this.getMethod(),
109 headers: this.headers
112 // For uploads we need to create an actual form that contains the file upload fields,
113 // and pass that to the ajax call so it can do its iframe-based submit method.
114 if (this.form.hasUpload()) {
115 formEl = ajaxOptions.form = this.buildForm();
116 ajaxOptions.isUpload = true;
118 ajaxOptions.params = this.getParams();
121 Ext.Ajax.request(ajaxOptions);
124 Ext.removeNode(formEl);
128 <span id='Ext-form-action-Submit-method-getParams'> /**
130 * Build the full set of parameters from the field values plus any additional configured params.
132 getParams: function() {
134 configParams = this.callParent(),
135 fieldParams = this.form.getValues(nope, nope, this.submitEmptyText !== nope);
136 return Ext.apply({}, fieldParams, configParams);
139 <span id='Ext-form-action-Submit-method-buildForm'> /**
141 * Build a form element containing fields corresponding to all the parameters to be
142 * submitted (everything returned by {@link #getParams}.
143 * NOTE: the form element is automatically added to the DOM, so any code that uses
144 * it must remove it from the DOM after finishing with it.
145 * @return HTMLFormElement
147 buildForm: function() {
151 basicForm = this.form,
152 params = this.getParams(),
155 basicForm.getFields().each(function(field) {
156 if (field.isFileUpload()) {
157 uploadFields.push(field);
161 function addField(name, val) {
166 value: Ext.String.htmlEncode(val)
170 // Add the form field values
171 Ext.iterate(params, function(key, val) {
172 if (Ext.isArray(val)) {
173 Ext.each(val, function(v) {
183 action: this.getUrl(),
184 method: this.getMethod(),
185 target: this.target || '_self',
186 style: 'display:none',
190 // Set the proper encoding for file uploads
191 if (uploadFields.length) {
192 formSpec.encoding = formSpec.enctype = 'multipart/form-data';
196 formEl = Ext.DomHelper.append(Ext.getBody(), formSpec);
198 // Special handling for file upload fields: since browser security measures prevent setting
199 // their values programatically, and prevent carrying their selected values over when cloning,
200 // we have to move the actual field instances out of their components and into the form.
201 Ext.Array.each(uploadFields, function(field) {
202 if (field.rendered) { // can only have a selected file value after being rendered
203 formEl.appendChild(field.extractFileInput());
212 <span id='Ext-form-action-Submit-method-onSuccess'> /**
215 onSuccess: function(response) {
216 var form = this.form,
218 result = this.processResponse(response);
219 if (result !== true && !result.success) {
221 form.markInvalid(result.errors);
223 this.failureType = Ext.form.action.Action.SERVER_INVALID;
226 form.afterAction(this, success);
229 <span id='Ext-form-action-Submit-method-handleResponse'> /**
232 handleResponse: function(response) {
233 var form = this.form,
234 errorReader = form.errorReader,
235 rs, errors, i, len, records;
237 rs = errorReader.read(response);
238 records = rs.records;
241 for(i = 0, len = records.length; i < len; i++) {
242 errors[i] = records[i].data;
245 if (errors.length < 1) {
249 success : rs.success,
253 return Ext.decode(response.responseText);