⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basicform.js

📁 Ext JS是一个创建丰富互联网应用程序的跨浏览器的JavaScrip库。它包含:高效率
💻 JS
📖 第 1 页 / 共 2 页
字号:
/*
 * Ext JS Library 3.0 Pre-alpha
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

/** * @class Ext.form.BasicForm * @extends Ext.util.Observable * <p>Encapsulates the DOM &lt;form> element at the heart of the {@link Ext.form.FormPanel FormPanel} class, and provides * input field management, validation, submission, and form loading services.</p> * <p>By default, Ext Forms are submitted through Ajax, using an instance of {@link Ext.form.Action.Submit}. * To enable normal browser submission of an Ext Form, use the {@link #standardSubmit} config option.</p> * <p><b><u>File Uploads</u></b></p> * <p>{@link #fileUpload File uploads} are not performed using Ajax submission, that * is they are <b>not</b> performed using XMLHttpRequests. Instead the form is submitted in the standard * manner with the DOM <tt>&lt;form></tt> element temporarily modified to have its * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer * to a dynamically generated, hidden <tt>&lt;iframe></tt> which is inserted into the document * but removed after the return data has been gathered.</p> * <p>The server response is parsed by the browser to create the document for the IFRAME. If the * server is using JSON to send the return object, then the * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p> * <p>Characters which are significant to an HTML parser must be sent as HTML entities, so encode * "&lt;" as "&amp;lt;", "&amp;" as "&amp;amp;" etc.</p> * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object * is created containing a <tt>responseText</tt> property in order to conform to the * requirements of event handlers and callbacks.</p> * <p>Be aware that file upload packets are sent with the content type <a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form</a> * and some server technologies (notably JEE) may require some custom processing in order to * retrieve parameter names and parameter values from the packet content.</p> * @constructor * @param {Mixed} el The form element or its id * @param {Object} config Configuration options */Ext.form.BasicForm = function(el, config){    Ext.apply(this, config);    /*     * @property items     * A {@link Ext.util.MixedCollection MixedCollection) containing all the Ext.form.Fields in this form.     * @type MixedCollection     */    this.items = new Ext.util.MixedCollection(false, function(o){        return o.itemId || o.id || (o.id = Ext.id());    });    this.addEvents(        /**         * @event beforeaction         * Fires before any action is performed. Return false to cancel the action.         * @param {Form} this         * @param {Action} action The {@link Ext.form.Action} to be performed         */        'beforeaction',        /**         * @event actionfailed         * Fires when an action fails.         * @param {Form} this         * @param {Action} action The {@link Ext.form.Action} that failed         */        'actionfailed',        /**         * @event actioncomplete         * Fires when an action is completed.         * @param {Form} this         * @param {Action} action The {@link Ext.form.Action} that completed         */        'actioncomplete'    );    if(el){        this.initEl(el);    }    Ext.form.BasicForm.superclass.constructor.call(this);};Ext.extend(Ext.form.BasicForm, Ext.util.Observable, {    /**     * @cfg {String} method     * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.     */    /**     * @cfg {DataReader} reader     * An Ext.data.DataReader (e.g. {@link Ext.data.XmlReader}) to be used to read data when executing "load" actions.     * This is optional as there is built-in support for processing JSON.     */    /**     * @cfg {DataReader} errorReader     * <p>An Ext.data.DataReader (e.g. {@link Ext.data.XmlReader}) to be used to read field error messages returned from "submit" actions.     * This is completely optional as there is built-in support for processing JSON.</p>     * <p>The Records which provide messages for the invalid Fields must use the Field name (or id) as the Record ID,     * and must contain a field called "msg" which contains the error message.</p>     * <p>The errorReader does not have to be a full-blown implementation of a DataReader. It simply needs to implement a      * <tt>read(xhr)</tt> function which returns an Array of Records in an object with the following structure:<pre><code>{    records: recordArray}</code></pre>     */    /**     * @cfg {String} url     * The URL to use for form actions if one isn't supplied in the {@link #doAction action} options.     */    /**     * @cfg {Boolean} fileUpload     * Set to true if this form is a file upload.     * <p>File uploads are not performed using normal "Ajax" techniques, that is they are <b>not</b>     * performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the     * DOM <tt>&lt;form></tt> element temporarily modified to have its     * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer     * to a dynamically generated, hidden <tt>&lt;iframe></tt> which is inserted into the document     * but removed after the return data has been gathered.</p>     * <p>The server response is parsed by the browser to create the document for the IFRAME. If the     * server is using JSON to send the return object, then the     * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header     * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p>     * <p>Characters which are significant to an HTML parser must be sent as HTML entities, so encode     * "&lt;" as "&amp;lt;", "&amp;" as "&amp;amp;" etc.</p>     * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object     * is created containing a <tt>responseText</tt> property in order to conform to the     * requirements of event handlers and callbacks.</p>     * <p>Be aware that file upload packets are sent with the content type <a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form</a>     * and some server technologies (notably JEE) may require some custom processing in order to     * retrieve parameter names and parameter values from the packet content.</p>     */    /**     * @cfg {Object} baseParams     * <p>Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.</p>     * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p>     */    /**     * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).     */    timeout: 30,    // private    activeAction : null,    /**     * @cfg {Boolean} trackResetOnLoad If set to <tt>true</tt>, {@link #reset}() resets to the last loaded     * or {@link #setValues}() data instead of when the form was first created.  Defaults to <tt>false</tt>.     */    trackResetOnLoad : false,    /**     * @cfg {Boolean} standardSubmit If set to true, standard HTML form submits are used instead of XHR (Ajax) style     * form submissions. (defaults to false)<br>     * <p><b>Note:</b> When using standardSubmit, the options to {@link #submit} are ignored because Ext's     * Ajax infrastracture is bypassed. To pass extra parameters (baseParams and params), you will need to     * create hidden fields within the form.</p>     * <p>The url config option is also bypassed, so set the action as well:</p>     * <pre><code>PANEL.getForm().getEl().dom.action = 'URL'     * </code></pre>     * An example encapsulating the above:     * <pre><code>new Ext.FormPanel({    standardSubmit: true,    baseParams: {        foo: 'bar'    },    url: "myProcess.php",    items: [{        xtype: "textfield",        name: "userName"    }],    buttons: [{        text: "Save",        handler: function(){            var O = this.ownerCt;            if (O.getForm().isValid()) {                if (O.url)                     O.getForm().getEl().dom.action = O.url;                if (O.baseParams) {                    for (i in O.baseParams) {                        O.add({                            xtype: "hidden",                            name: i,                            value: O.baseParams[i]                        })                    }                    O.doLayout();                }                O.getForm().submit();            }        }    }]});     * </code></pre>     */    /**     * By default wait messages are displayed with Ext.MessageBox.wait. You can target a specific     * element by passing it or its id or mask the form itself by passing in true.     * @type Mixed     * @property waitMsgTarget     */    // private    initEl : function(el){        this.el = Ext.get(el);        this.id = this.el.id || Ext.id();        if(!this.standardSubmit){            this.el.on('submit', this.onSubmit, this);        }        this.el.addClass('x-form');    },    /**     * Get the HTML form Element     * @return Ext.Element     */    getEl: function(){        return this.el;    },    // private    onSubmit : function(e){        e.stopEvent();    },    // private    destroy: function() {        this.items.each(function(f){            Ext.destroy(f);        });        if(this.el){            this.el.removeAllListeners();            this.el.remove();        }        this.purgeListeners();    },    /**     * Returns true if client-side validation on the form is successful.     * @return Boolean     */    isValid : function(){        var valid = true;        this.items.each(function(f){           if(!f.validate()){               valid = false;           }        });        return valid;    },    /**     * <p>Returns true if any fields in this form have changed from their original values.</p>     * <p>Note that if this BasicForm was configured with {@link #trackResetOnLoad} then the     * Fields' <i>original values</i> are updated when the values are loaded by {@link #setValues}     * or {@link #loadRecord}.</p>     * @return Boolean     */    isDirty : function(){        var dirty = false;        this.items.each(function(f){           if(f.isDirty()){               dirty = true;               return false;           }        });        return dirty;    },    /**     * Performs a predefined action ({@link Ext.form.Action.Submit} or     * {@link Ext.form.Action.Load}) or a custom extension of {@link Ext.form.Action}      * to perform application-specific processing.     * @param {String/Object} actionName The name of the predefined action type,     * or instance of {@link Ext.form.Action} to perform.     * @param {Object} options (optional) The options to pass to the {@link Ext.form.Action}.      * All of the config options listed below are supported by both the submit     * and load actions unless otherwise noted (custom actions could also accept     * other config options):<ul>     * <li><b>url</b> : String<p class="sub-desc">The url for the action (defaults     * to the form's {@link #url}.)</p></li>     * <li><b>method</b> : String<p class="sub-desc">The form method to use (defaults     * to the form's method, or POST if not defined)</p></li>     * <li><b>params</b> : String/Object<div class="sub-desc"><p>The params to pass     * (defaults to the form's baseParams, or none if not defined)</p>     * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p></div></li>     * <li><b>headers</b> : Object<p class="sub-desc">Request headers to set for the action     * (defaults to the form's default headers)</p></li>     * <li><b>success</b> : Function<p class="sub-desc">The callback that will     * be invoked after a successful response. The function is passed the following parameters:<ul>     * <li><tt>form</tt> : Ext.form.BasicForm<div class="sub-desc">The form that requested the action</div></li>     * <li><tt>action</tt> : The {@link Ext.form.Action Action} object which performed the operation.     * <div class="sub-desc">The action object contains these properties of interest:<ul>     * <li><tt>{@link Ext.form.Action#response response}</tt></li>     * <li><tt>{@link Ext.form.Action#result result}</tt> : interrogate for custom postprocessing</li>     * <li><tt>{@link Ext.form.Action#type type}</tt></li>     * </ul></p></li>     * <li><b>failure</b> : Function     * <div class="sub-desc">     * <p>The callback that will be invoked after a failed transaction attempt. The function is     * passed the following parameters:</p><ul>     * <li><tt>form</tt> : The {@link Ext.form.BasicForm} that requested the action.      * <div class="sub-desc"></div></li>     * <li><tt>action</tt> : The {@link Ext.form.Action Action} object which performed the operation.     * <div class="sub-desc">The action object contains these properties of interest:<ul>     * <li><tt>{@link Ext.form.Action#failureType failureType}</tt></li>     * <li><tt>{@link Ext.form.Action#response response}</tt></li>     * <li><tt>{@link Ext.form.Action#result result}</tt> : interrogate for custom postprocessing</li>     * <li><tt>{@link Ext.form.Action#type type}</tt></li>     * </ul></div></li></ul>     * </div></li>     * <li><b>scope</b> : Object<p class="sub-desc">The scope in which to call the     * callback functions (The <tt>this</tt> reference for the callback functions).</p></li>     * <li><b>clientValidation</b> : Boolean<p class="sub-desc">Submit Action only.     * Determines whether a Form's fields are validated in a final call to     * {@link Ext.form.BasicForm#isValid isValid} prior to submission. Set to <tt>false</tt>     * to prevent this. If undefined, pre-submission field validation is performed.</p></li></ul>     * @return {BasicForm} this     */    doAction : function(action, options){        if(typeof action == 'string'){            action = new Ext.form.Action.ACTION_TYPES[action](this, options);        }        if(this.fireEvent('beforeaction', this, action) !== false){            this.beforeAction(action);            action.run.defer(100, action);        }        return this;    },    /**     * Shortcut to {@link #doAction do} a {@link Ext.form.Action.Submit submit action}.     * @param {Object} options The options to pass to the action (see {@link #doAction} for details).<br>     * <p><b>Note:</b> this is ignored when using the {@link #standardSubmit} option.</p>     * <p>The following code:</p><pre><code>myFormPanel.getForm().submit({    clientValidation: true,    url: 'updateConsignment.php',    params: {        newStatus: 'delivered'

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -