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,412
    Vote Rating
    1288
      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!

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

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,790
    Vote Rating
    390
      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
  •