3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
15 Ext.ns('Ext.ux.form');
17 <div id="cls-Ext.ux.form.SelectBox"></div>/**
18 * @class Ext.ux.form.SelectBox
19 * @extends Ext.form.ComboBox
20 * <p>Makes a ComboBox more closely mimic an HTML SELECT. Supports clicking and dragging
21 * through the list, with item selection occurring when the mouse button is released.
22 * When used will automatically set {@link #editable} to false and call {@link Ext.Element#unselectable}
23 * on inner elements. Re-enabling editable after calling this will NOT work.</p>
24 * @author Corey Gilmore http://extjs.com/forum/showthread.php?t=6392
25 * @history 2007-07-08 jvs
26 * Slight mods for Ext 2.0
29 Ext.ux.form.SelectBox = Ext.extend(Ext.form.ComboBox, {
30 constructor: function(config){
31 this.searchResetDelay = 1000;
32 config = config || {};
33 config = Ext.apply(config || {}, {
37 lastSearchTerm: false,
42 Ext.ux.form.SelectBox.superclass.constructor.apply(this, arguments);
44 this.lastSelectedIndex = this.selectedIndex || 0;
47 initEvents : function(){
48 Ext.ux.form.SelectBox.superclass.initEvents.apply(this, arguments);
49 // you need to use keypress to capture upper/lower case and shift+key, but it doesn't work in IE
50 this.el.on('keydown', this.keySearch, this, true);
51 this.cshTask = new Ext.util.DelayedTask(this.clearSearchHistory, this);
54 keySearch : function(e, target, options) {
56 var key = String.fromCharCode(raw);
59 if( !this.store.getCount() ) {
64 case Ext.EventObject.HOME:
69 case Ext.EventObject.END:
74 case Ext.EventObject.PAGEDOWN:
75 this.selectNextPage();
79 case Ext.EventObject.PAGEUP:
80 this.selectPrevPage();
85 // skip special keys other than the shift key
86 if( (e.hasModifier() && !e.shiftKey) || e.isNavKeyPress() || e.isSpecialKey() ) {
89 if( this.lastSearchTerm == key ) {
90 startIndex = this.lastSelectedIndex;
92 this.search(this.displayField, key, startIndex);
93 this.cshTask.delay(this.searchResetDelay);
96 onRender : function(ct, position) {
97 this.store.on('load', this.calcRowsPerPage, this);
98 Ext.ux.form.SelectBox.superclass.onRender.apply(this, arguments);
99 if( this.mode == 'local' ) {
101 this.calcRowsPerPage();
105 onSelect : function(record, index, skipCollapse){
106 if(this.fireEvent('beforeselect', this, record, index) !== false){
107 this.setValue(record.data[this.valueField || this.displayField]);
108 if( !skipCollapse ) {
111 this.lastSelectedIndex = index + 1;
112 this.fireEvent('select', this, record, index);
116 afterRender : function() {
117 Ext.ux.form.SelectBox.superclass.afterRender.apply(this, arguments);
119 this.el.swallowEvent('mousedown', true);
121 this.el.unselectable();
122 this.innerList.unselectable();
123 this.trigger.unselectable();
124 this.innerList.on('mouseup', function(e, target, options) {
125 if( target.id && target.id == this.innerList.id ) {
131 this.innerList.on('mouseover', function(e, target, options) {
132 if( target.id && target.id == this.innerList.id ) {
135 this.lastSelectedIndex = this.view.getSelectedIndexes()[0] + 1;
136 this.cshTask.delay(this.searchResetDelay);
139 this.trigger.un('click', this.onTriggerClick, this);
140 this.trigger.on('mousedown', function(e, target, options) {
142 this.onTriggerClick();
145 this.on('collapse', function(e, target, options) {
146 Ext.getDoc().un('mouseup', this.collapseIf, this);
149 this.on('expand', function(e, target, options) {
150 Ext.getDoc().on('mouseup', this.collapseIf, this);
154 clearSearchHistory : function() {
155 this.lastSelectedIndex = 0;
156 this.lastSearchTerm = false;
159 selectFirst : function() {
160 this.focusAndSelect(this.store.data.first());
163 selectLast : function() {
164 this.focusAndSelect(this.store.data.last());
167 selectPrevPage : function() {
168 if( !this.rowHeight ) {
171 var index = Math.max(this.selectedIndex-this.rowsPerPage, 0);
172 this.focusAndSelect(this.store.getAt(index));
175 selectNextPage : function() {
176 if( !this.rowHeight ) {
179 var index = Math.min(this.selectedIndex+this.rowsPerPage, this.store.getCount() - 1);
180 this.focusAndSelect(this.store.getAt(index));
183 search : function(field, value, startIndex) {
184 field = field || this.displayField;
185 this.lastSearchTerm = value;
186 var index = this.store.find.apply(this.store, arguments);
188 this.focusAndSelect(index);
192 focusAndSelect : function(record) {
193 var index = Ext.isNumber(record) ? record : this.store.indexOf(record);
194 this.select(index, this.isExpanded());
195 this.onSelect(this.store.getAt(index), index, this.isExpanded());
198 calcRowsPerPage : function() {
199 if( this.store.getCount() ) {
200 this.rowHeight = Ext.fly(this.view.getNode(0)).getHeight();
201 this.rowsPerPage = this.maxHeight / this.rowHeight;
203 this.rowHeight = false;
209 Ext.reg('selectbox', Ext.ux.form.SelectBox);
212 Ext.ux.SelectBox = Ext.ux.form.SelectBox;