Results 1 to 4 of 4

Thread: How do you get the Displayed Field value from a combobox?

  1. #1
    Sencha User
    Join Date
    Dec 2010
    Posts
    4

    Default How do you get the Displayed Field value from a combobox?

    Hello,

    I am using a comboBox and I use the getValue() method which works well, but I also want to use the displayed text for the item I selected. How do I get that?

    Regards,

  2. #2
    Sencha User
    Join Date
    Dec 2010
    Posts
    4

    Default

    I've got it!!
    You get the selected text from the store.
    Code:
     
    var cms_committee_record = Ext.data.Record.create([              
                    {
                        name: 'key'
                    },
                    {
                        name: 'committee'                   
                    }                 
               ]);
    ...
     
    var key= Ext.getCmp(comboBoxId).getValue(); 
        var rindex= cms_committee_store.find('key',key);
        var cRecord = cms_committee_store.getAt(rindex);
        var selectedText = cRecord.get('committee');
    Last edited by hannas; 21 Jan 2011 at 3:34 PM. Reason: missed the getValue() method

  3. #3
    Sencha Premium Member rivarecords's Avatar
    Join Date
    Apr 2010
    Location
    Fredrock, MD
    Posts
    24

    Default

    Yep, that's it and then you could add a method:

    Code:
    {xtype: 'combo',
        fieldLabel:'Some Combo',
        id:'some_combo',
        store: some_combo_store, 
        mode:'local',
        valueField: 'value',
        displayField: 'text',
        getDisplayedText: function(v) {
          var val = this.valueField;
          var text = this.displayField;
          var cbval = this.value;
          var displayedText = '';
          Ext.each(this.store.getRange(0,this.store.getCount()), function(row){  
          if(row.get(val)==cbval){displayedText =  row.get(text)}
         })
         return displayedText;
         }
        }
    And then call it like:
    Code:
    var selectedText = Ext.getCmp(some_combo).getDisplayedText()

  4. #4

    Default

    Store.getById
    Wes

Similar Threads

  1. Cross icon of search field is not displayed in iphone
    By Shijutv in forum Sencha Touch 1.x: Discussion
    Replies: 4
    Last Post: 3 Feb 2012, 2:17 AM
  2. Help: form field values not displayed
    By SchattenMann in forum Ext 3.x: Help & Discussion
    Replies: 7
    Last Post: 31 Aug 2009, 3:06 AM
  3. Replies: 0
    Last Post: 5 Nov 2008, 7:14 AM

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
  •