问题
I am using extjs 4.0.7. I want to disabled tab and Enter key event when user using Combobox. I have tried to use keyUp and KeyDown event. But I didn't get any alert for it.
Here is my code:
{
xtype: 'combo',
store: ds,
id:'UserBO_SelectComponentId',
displayField: 'displayName',
valueField: 'userId',
typeAhead: false,
hideLabel: true,
disabled: false,
hideTrigger:true,
multiSelect:true,
delimiter: ";",
anchor: '100%',
triggerAction: 'all',
listeners: {
change: function( comboField, newValue, oldValue, eOpts ){
selectUserCallBack2(newValue,'UserBO_SelectComponentId',comboField,oldValue);
},
select:function(comboField,oldValue){
testRec(comboField,oldValue)
},
keypress:function(comboField,e){
disabledKeysOnKeyup(comboField,e)
}
},
listConfig: {
loadingText: 'Searching...',
enableKeyEvents: true,
emptyText: 'No matching posts found.'
},
pageSize: 10
}
Can anyone please suggest what is the problem here?
回答1:
The keyup, keydown and keypressed events only fire if enableKeyEvents is set to true. Default this is set to false, so you need to add enableKeyEvents:true
to the combobox config. And then do special treatment for enter and tab key.
回答2:
You don't need to listen to key events and tab into that. What you want to do is set autoSelect
to false. It's true by default. When set to false the user has to manually highlight an item before pressing the enter or tab key to select it (unless the value of typeAhead were true), or use the mouse to select a value.
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.ComboBox-cfg-autoSelect
来源:https://stackoverflow.com/questions/10630667/extjs-4-combobox-how-to-disabled-tab-and-enter-key