Search code examples
extjsextjs4

Remote query with combobox on Enter hit


I have a combobox which has a remote store. When a user writes down three or more letters, I see a server request, but I want to fire this request when the user hits Enter button. At this moment my combo has these properties:

forceSelection:true,
enableKeyEvents:true,
listeners:{
    keyup:function(){ // I prevent "normal" server requests in this manner
        return false;
    },
    keydown:function(){
        return false;
    },
    keypress: function() {
        return false;
    },
    specialkey:function(a,b,c){
        if(b.keyCode==13){
            // But at this moment I want to make a request          
        }
    }
}

Solution

  • You can set 'minChars' to an extremely high value, to disable value selection on typing. http://docs.sencha.com/extjs/4.2.3/#!/api/Ext.form.field.ComboBox-cfg-minChars

    Then expand the combobox selection on enter key:

    forceSelection:true,
    enableKeyEvents:true,
    // show value selection after typing 999 chars
    minChars: 999,
    // set triggerAction to 'query' to show only filtered results after pressing enter
    triggerAction: 'query',
    listeners: {
        specialkey: function (combobox, e) {
            if (e.keyCode == 13) {
                combobox.expand();
            }
        }
    }