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

📄 combo.js

📁 ext-2.3.0
💻 JS
📖 第 1 页 / 共 3 页
字号:
/*
 * Ext JS Library 2.3.0
 * Copyright(c) 2006-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

/** * @class Ext.form.ComboBox * @extends Ext.form.TriggerField * <p>A combobox control with support for autocomplete, remote-loading, paging and many other features.</p> * A ComboBox works in a similar manner to a traditional HTML &lt;select> field. The difference is that to submit the * {@link #valueField}, you must specify a {@link #hiddenName} to create a hidden input field to hold the * value of the valueField. The <i>{@link #displayField}</i> is shown in the text field which is named * according to the {@link #name}. * @constructor * Create a new ComboBox. * @param {Object} config Configuration options */Ext.form.ComboBox = Ext.extend(Ext.form.TriggerField, {    /**     * @cfg {Mixed} transform The id, DOM node or element of an existing HTML SELECT to convert to a ComboBox.     * Note that if you specify this and the combo is going to be in a {@link Ext.form.BasicForm} or     * {@link Ext.form.FormPanel}, you must also set {@link #lazyRender} = true.     */    /**     * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when     * rendering into an Ext.Editor, defaults to false).     */    /**     * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:     * {tag: "input", type: "text", size: "24", autocomplete: "off"})     */    /**     * @cfg {Ext.data.Store/Array} store The data source to which this combo is bound (defaults to undefined).  This can be     * any {@link Ext.data.Store} subclass, a 1-dimensional array (e.g., ['Foo','Bar']) or a 2-dimensional array (e.g.,     * [['f','Foo'],['b','Bar']]).  Arrays will be converted to a {@link Ext.data.SimpleStore} internally.     * 1-dimensional arrays will automatically be expanded (each array item will be the combo value and text) and     * for multi-dimensional arrays, the value in index 0 of each item will be assumed to be the combo value, while     * the value at index 1 is assumed to be the combo text.     */    /**     * @cfg {String} title If supplied, a header element is created containing this text and added into the top of     * the dropdown list (defaults to undefined, with no header element)     */    // private    defaultAutoCreate : {tag: "input", type: "text", size: "24", autocomplete: "off"},    /**     * @cfg {Number} listWidth The width (used as a parameter to {@link Ext.Element#setWidth}) of the dropdown list (defaults to the width of the ComboBox field)     */    /**     * @cfg {String} displayField The underlying data field name to bind to this ComboBox (defaults to undefined if     * mode = 'remote' or 'text' if transforming a select)     */    /**     * @cfg {String} valueField The underlying data value name to bind to this ComboBox (defaults to undefined if     * mode = 'remote' or 'value' if transforming a select) Note: use of a valueField requires the user to make a selection     * in order for a value to be mapped.     */    /**     * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the     * field's data value (defaults to the underlying DOM element's name). Required for the combo's value to automatically     * post during a form submission.  Note that the hidden field's id will also default to this name if {@link #hiddenId}     * is not specified.  The combo's id and the hidden field's ids should be different, since no two DOM nodes should     * share the same id, so if the combo and hidden names are the same, you should specify a unique hiddenId.     */    /**     * @cfg {String} hiddenId If {@link #hiddenName} is specified, hiddenId can also be provided to give the hidden field     * a unique id (defaults to the hiddenName).  The hiddenId and combo {@link #id} should be different, since no two DOM     * nodes should share the same id.     */    /**     * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')     */    listClass: '',    /**     * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')     */    selectedClass: 'x-combo-selected',    /**     * @cfg {String} triggerClass An additional CSS class used to style the trigger button.  The trigger will always get the     * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-arrow-trigger'     * which displays a downward arrow icon).     */    triggerClass : 'x-form-arrow-trigger',    /**     * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right     */    shadow:'sides',    /**     * @cfg {String} listAlign A valid anchor position value. See {@link Ext.Element#alignTo} for details on supported     * anchor positions (defaults to 'tl-bl')     */    listAlign: 'tl-bl?',    /**     * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)     */    maxHeight: 300,    /**     * @cfg {Number} minHeight The minimum height in pixels of the dropdown list when the list is constrained by its     * distance to the viewport edges (defaults to 90)     */    minHeight: 90,    /**     * @cfg {String} triggerAction The action to execute when the trigger is clicked.  Use 'all' to run the     * query specified by the allQuery config option (defaults to 'query')     */    triggerAction: 'query',    /**     * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate     * (defaults to 4 if remote or 0 if local, does not apply if editable = false)     */    minChars : 4,    /**     * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable     * delay ({@link #typeAheadDelay}) if it matches a known value (defaults to false)     */    typeAhead: false,    /**     * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the     * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')     */    queryDelay: 500,    /**     * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the     * filter queries will execute with page start and limit parameters.  Only applies when mode = 'remote' (defaults to 0)     */    pageSize: 0,    /**     * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus.  Only applies     * when editable = true (defaults to false)     */    selectOnFocus:false,    /**     * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')     */    queryParam: 'query',    /**     * @cfg {String} loadingText The text to display in the dropdown list while data is loading.  Only applies     * when mode = 'remote' (defaults to 'Loading...')     */    loadingText: 'Loading...',    /**     * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)     */    resizable: false,    /**     * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)     */    handleHeight : 8,    /**     * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a     * traditional select (defaults to true)     */    editable: true,    /**     * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')     */    allQuery: '',    /**     * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)     */    mode: 'remote',    /**     * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if     * listWidth has a higher value)     */    minListWidth : 70,    /**     * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to     * allow the user to set arbitrary text into the field (defaults to false)     */    forceSelection:false,    /**     * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed     * if typeAhead = true (defaults to 250)     */    typeAheadDelay : 250,    /**     * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in     * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined). If this     * defaut text is used, it means there is no value set and no validation will occur on this field.     */    /**     * @cfg {Boolean} lazyInit True to not initialize the list for this combo until the field is focused (defaults to true)     */    lazyInit : true,    /**     * The value of the match string used to filter the store. Delete this property to force a requery.     * Example use:<pre><code>var combo = new Ext.form.ComboBox({    ...    mode: 'remote',    ...    listeners: {        // delete the previous query in the beforequery event or set         // combo.lastQuery = null (this will reload the store the next time it expands)        beforequery: function(qe){            delete qe.combo.lastQuery;        }    }});</code></pre>     * @property lastQuery     * @type String     */    // private    initComponent : function(){        Ext.form.ComboBox.superclass.initComponent.call(this);        this.addEvents(            /**             * @event expand             * Fires when the dropdown list is expanded             * @param {Ext.form.ComboBox} combo This combo box             */            'expand',            /**             * @event collapse             * Fires when the dropdown list is collapsed             * @param {Ext.form.ComboBox} combo This combo box             */            'collapse',            /**             * @event beforeselect             * Fires before a list item is selected. Return false to cancel the selection.             * @param {Ext.form.ComboBox} combo This combo box             * @param {Ext.data.Record} record The data record returned from the underlying store             * @param {Number} index The index of the selected item in the dropdown list             */            'beforeselect',            /**             * @event select             * Fires when a list item is selected             * @param {Ext.form.ComboBox} combo This combo box             * @param {Ext.data.Record} record The data record returned from the underlying store             * @param {Number} index The index of the selected item in the dropdown list             */            'select',            /**             * @event beforequery             * Fires before all queries are processed. Return false to cancel the query or set the queryEvent's             * cancel property to true.             * @param {Object} queryEvent An object that has these properties:<ul>             * <li><code>combo</code> : Ext.form.ComboBox <div class="sub-desc">This combo box</div></li>             * <li><code>query</code> : String <div class="sub-desc">The query</div></li>             * <li><code>forceAll</code> : Boolean <div class="sub-desc">True to force "all" query</div></li>             * <li><code>cancel</code> : Boolean <div class="sub-desc">Set to true to cancel the query</div></li>             * </ul>             */            'beforequery'        );        if(this.transform){            this.allowDomMove = false;            var s = Ext.getDom(this.transform);            if(!this.hiddenName){                this.hiddenName = s.name;            }            if(!this.store){                this.mode = 'local';                var d = [], opts = s.options;                for(var i = 0, len = opts.length;i < len; i++){                    var o = opts[i],                        value = (o.hasAttribute ? o.hasAttribute('value') : o.getAttributeNode('value').specified) ? o.value : o.text;                    if(o.selected) {                        this.value = value;                    }                    d.push([value, o.text]);                }                this.store = new Ext.data.SimpleStore({                    'id': 0,                    fields: ['value', 'text'],                    data : d                });                this.valueField = 'value';                this.displayField = 'text';            }            s.name = Ext.id(); // wipe out the name in case somewhere else they have a reference            if(!this.lazyRender){                this.target = true;                this.el = Ext.DomHelper.insertBefore(s, this.autoCreate || this.defaultAutoCreate);                Ext.removeNode(s); // remove it                this.render(this.el.parentNode);            }else{                Ext.removeNode(s); // remove it            }        }        //auto-configure store from local array data        else if(Ext.isArray(this.store)){            if (Ext.isArray(this.store[0])){                this.store = new Ext.data.SimpleStore({                    fields: ['value','text'],                    data: this.store                });                this.valueField = 'value';            }else{                this.store = new Ext.data.SimpleStore({                    fields: ['text'],                    data: this.store,                    expandData: true                });                this.valueField = 'text';            }            this.displayField = 'text';            this.mode = 'local';        }        this.selectedIndex = -1;        if(this.mode == 'local'){            if(this.initialConfig.queryDelay === undefined){                this.queryDelay = 10;            }            if(this.initialConfig.minChars === undefined){                this.minChars = 0;            }        }    },    // private    onRender : function(ct, position){        Ext.form.ComboBox.superclass.onRender.call(this, ct, position);        if(this.hiddenName){            this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName,                    id: (this.hiddenId||this.hiddenName)}, 'before', true);            // prevent input submission            this.el.dom.removeAttribute('name');        }        if(Ext.isGecko){            this.el.dom.setAttribute('autocomplete', 'off');        }        if(!this.lazyInit){            this.initList();        }else{            this.on('focus', this.initList, this, {single: true});        }        if(!this.editable){            this.editable = true;            this.setEditable(false);        }    },    // private    initValue : function(){        Ext.form.ComboBox.superclass.initValue.call(this);

⌨️ 快捷键说明

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