Results 1 to 4 of 4

Thread: combo box - select a value on key press

  1. #1
    Ext JS Premium Member
    Join Date
    Dec 2011
    Posts
    29
    Vote Rating
    0
      0  

    Default combo box - select a value on key press

    Hi,

    I'm looking for a very obvious behavior of HTML select in ExtJs 4 combo box.
    If I press in a key then the control should move to combo box value starting from that key. How can I achieve this.

    I have tried
    Code:
    queryMode:'local'
    which is doing same kind of thing but its allowing editing in combo box. I dont want to make it editable.

    Here is code for my combo box

    Code:
    {
     xtype: 'combobox',
     fieldLabel: 'Choose Country',
     store: states,
     queryMode: 'local',
     hideTrigger:true,             
     displayField: 'name',
     valueField: 'abbr'             
    }
    Please suggest how to achieve this

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,554
    Vote Rating
    1272
      0  

    Default

    For this you'd have to set the editable config to false so that the person could not type in the input. You'd have to capture the keydown event and then scroll to the first/best match.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,790
    Vote Rating
    391
      0  

    Default

    Code:
    Ext.create('Ext.form.field.ComboBox', {
        editable: false,
        enableKeyEvents: true,
        renderTo: Ext.getBody(),
        store: ['Volvo', 'Saab', 'Fiat', 'Audi'],
    
        listeners: {
            keyup: function(combo, event) {
                var key = String.fromCharCode(event.getKey()),
                    boundList = combo.getPicker(),
                    store = boundList.getStore(),
                    record = store.findRecord(combo.displayField, key);
    
                if (record) {
                    boundList.highlightItem(boundList.getNode(record));
                }
            }
        }
    });

  4. #4
    Ext JS Premium Member
    Join Date
    Dec 2011
    Posts
    29
    Vote Rating
    0
      0  

    Default Its working fine

    Hi,

    Thanks!!

    Its working fine.


    Thanks a lot.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •