PDA

View Full Version : ComboBox : allow query to fire when field not focused


Saeven
11-18-2008, 10:15 AM
I'm in a situation where a store should be permitted to fire even if not focused. It would be nice if there were a 'requireFocus' parameter, and then:


// private
onBeforeLoad : function(){
if(this.requireFocus && !this.hasFocus){
return;
}

this.innerList.update(this.loadingText ?
'<div class="loading-indicator">'+this.loadingText+'</div>' : '');
this.restrictHeight();
this.selectedIndex = -1;
},

// private
onLoad : function(){
if(this.requireFocus && !this.hasFocus){
return;
}

if(this.store.getCount() > 0){
this.expand();
this.restrictHeight();
if(this.lastQuery == this.allQuery){
if(this.editable){
this.el.dom.select();
}
if(!this.selectByValue(this.value, true)){
this.select(0, true);
}
}else{
this.selectNext();
if(this.typeAhead && this.lastKey != Ext.EventObject.BACKSPACE && this.lastKey != Ext.EventObject.DELETE){
this.taTask.delay(this.typeAheadDelay);
}
}
}else{
this.onEmptyResults();
}
//this.el.focus();
}



Cheers.
A

mystix
11-18-2008, 10:28 AM
what's the use case for this? :-/

Saeven
11-18-2008, 10:36 AM
In this particular case, it's a user selector based on first name + last name, that doubly serves as a quick-creation mechanism. The form serves to insert people into an org chart, and contains:

- name combo
- email field (also auto-completed when the 'select' event is fired on the combo)
- company title

The logic on the back end, is that if the name is unique during the combo's store query, it will return the name, email and user id (a table guid). The combo has a hiddenName that sends this value during form submission.

So for example, you could type 'Jack Slocum' into the combo's text field, and quickly tab down to the next field. If the first/last name exists and is unique, the guid is not fetched if we have a quick typist that tabs to the next field.

Combined with my previous request (which seems fundamental) of having the hidden value reset if no match is found:

onEmptyResults: function(){
this.collapse();
this.hiddenField.value = '';
},


We have a system where the combobox will always have a proper hidden value when:

A. There are, or aren't results to match the input
B. The user has tabbed out of the field

Hope this makes sense.
A