3
* Copyright(c) 2006-2009 Ext JS, LLC
5
* http://www.extjs.com/license
10
* @class Ext.ux.form.SelectBox
11
* @extends Ext.form.ComboBox
12
* <p>Makes a ComboBox more closely mimic an HTML SELECT. Supports clicking and dragging
13
* through the list, with item selection occurring when the mouse button is released.
14
* When used will automatically set {@link #editable} to false and call {@link Ext.Element#unselectable}
15
* on inner elements. Re-enabling editable after calling this will NOT work.</p>
16
* @author Corey Gilmore http://extjs.com/forum/showthread.php?t=6392
17
* @history 2007-07-08 jvs
18
* Slight mods for Ext 2.0
21
Ext.ux.form.SelectBox = Ext.extend(Ext.form.ComboBox, {
22
constructor: function(config){
23
this.searchResetDelay = 1000;
24
config = config || {};
25
config = Ext.apply(config || {}, {
29
lastSearchTerm: false,
34
Ext.ux.form.SelectBox.superclass.constructor.apply(this, arguments);
36
this.lastSelectedIndex = this.selectedIndex || 0;
39
initEvents : function(){
40
Ext.ux.form.SelectBox.superclass.initEvents.apply(this, arguments);
41
// you need to use keypress to capture upper/lower case and shift+key, but it doesn't work in IE
42
this.el.on('keydown', this.keySearch, this, true);
43
this.cshTask = new Ext.util.DelayedTask(this.clearSearchHistory, this);
46
keySearch : function(e, target, options) {
48
var key = String.fromCharCode(raw);
51
if( !this.store.getCount() ) {
56
case Ext.EventObject.HOME:
61
case Ext.EventObject.END:
66
case Ext.EventObject.PAGEDOWN:
67
this.selectNextPage();
71
case Ext.EventObject.PAGEUP:
72
this.selectPrevPage();
77
// skip special keys other than the shift key
78
if( (e.hasModifier() && !e.shiftKey) || e.isNavKeyPress() || e.isSpecialKey() ) {
81
if( this.lastSearchTerm == key ) {
82
startIndex = this.lastSelectedIndex;
84
this.search(this.displayField, key, startIndex);
85
this.cshTask.delay(this.searchResetDelay);
88
onRender : function(ct, position) {
89
this.store.on('load', this.calcRowsPerPage, this);
90
Ext.ux.form.SelectBox.superclass.onRender.apply(this, arguments);
91
if( this.mode == 'local' ) {
92
this.calcRowsPerPage();
96
onSelect : function(record, index, skipCollapse){
97
if(this.fireEvent('beforeselect', this, record, index) !== false){
98
this.setValue(record.data[this.valueField || this.displayField]);
102
this.lastSelectedIndex = index + 1;
103
this.fireEvent('select', this, record, index);
107
render : function(ct) {
108
Ext.ux.form.SelectBox.superclass.render.apply(this, arguments);
110
this.el.swallowEvent('mousedown', true);
112
this.el.unselectable();
113
this.innerList.unselectable();
114
this.trigger.unselectable();
115
this.innerList.on('mouseup', function(e, target, options) {
116
if( target.id && target.id == this.innerList.id ) {
122
this.innerList.on('mouseover', function(e, target, options) {
123
if( target.id && target.id == this.innerList.id ) {
126
this.lastSelectedIndex = this.view.getSelectedIndexes()[0] + 1;
127
this.cshTask.delay(this.searchResetDelay);
130
this.trigger.un('click', this.onTriggerClick, this);
131
this.trigger.on('mousedown', function(e, target, options) {
133
this.onTriggerClick();
136
this.on('collapse', function(e, target, options) {
137
Ext.getDoc().un('mouseup', this.collapseIf, this);
140
this.on('expand', function(e, target, options) {
141
Ext.getDoc().on('mouseup', this.collapseIf, this);
145
clearSearchHistory : function() {
146
this.lastSelectedIndex = 0;
147
this.lastSearchTerm = false;
150
selectFirst : function() {
151
this.focusAndSelect(this.store.data.first());
154
selectLast : function() {
155
this.focusAndSelect(this.store.data.last());
158
selectPrevPage : function() {
159
if( !this.rowHeight ) {
162
var index = Math.max(this.selectedIndex-this.rowsPerPage, 0);
163
this.focusAndSelect(this.store.getAt(index));
166
selectNextPage : function() {
167
if( !this.rowHeight ) {
170
var index = Math.min(this.selectedIndex+this.rowsPerPage, this.store.getCount() - 1);
171
this.focusAndSelect(this.store.getAt(index));
174
search : function(field, value, startIndex) {
175
field = field || this.displayField;
176
this.lastSearchTerm = value;
177
var index = this.store.find.apply(this.store, arguments);
179
this.focusAndSelect(index);
183
focusAndSelect : function(record) {
184
var index = typeof record === 'number' ? record : this.store.indexOf(record);
185
this.select(index, this.isExpanded());
186
this.onSelect(this.store.getAt(record), index, this.isExpanded());
189
calcRowsPerPage : function() {
190
if( this.store.getCount() ) {
191
this.rowHeight = Ext.fly(this.view.getNode(0)).getHeight();
192
this.rowsPerPage = this.maxHeight / this.rowHeight;
194
this.rowHeight = false;
200
Ext.reg('selectbox', Ext.ux.form.SelectBox);
203
Ext.ux.SelectBox = Ext.ux.form.SelectBox;