Results 1 to 4 of 4

Thread: [SOLVED] How to get the Text value from a ComboBox

  1. #1

    Default [SOLVED] How to get the Text value from a ComboBox

    I have a combobox where I want to allow the user to select an item from the dropdown list, or enter in directly a new value.

    I created a quick example (no store) here:
    http://jsbin.com/elala

    If you SUBMIT with no inputs you will see a Quicktip telling you that the field is required.
    However, if you enter any text into the combobox, it will pass the validation, but will the fields value will be "".

    the source code can be edited at:
    http://jsbin.com/elala/edit

    thx for the help

    PHP Code:
    Ext.onReady(function(){

        var 
    combo = new Ext.form.ComboBox({
            
    allowBlankfalse,
            
    forceSelectionfalse,
            
    anchor:'95%',
            
    typeAheadfalse,
            
    mode'local',
            
    fieldLabel'Value',
            
    displayField:'value',
            
    valueField'value',
            
    hiddenName'value',
            
    name'value',
            
    requiredtrue
        
    })

        var 
    = new Ext.FormPanel({
            
    title'My Panel',
            
    collapsible:true,
            
    renderTo'container',
            
    width:400,
            
    height200,
            
    items: [combo],
            
    buttons: [{ 
              
    text'submit',
              
    scopethis,
              
    handler: function() {
                if(
    p.getForm().isValid()) {
                  
    vals p.getForm().getValues();
                  
    alert("Combo box value: " vals.value);
                  
    console.debug(vals);
                }
              }
              }]
        });
    }) 

  2. #2

    Default

    Hi,

    Try doing this add id: 'MyComboBox' to the combo box instance. In form panel submit button handler function write this code

    if(p.getForm().isValid()) {

    var form = p.getForm();

    var myComboBox = form.getComponent('MyComboBox');

    alert("Combo box value: " + myComboBox.getValue());



    }

  3. #3
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    If there are not seperate value and text fields, then you don't need a hiddenName do you? Think about it.

    You will be submitting a multi-values input. Both holding the same value!

  4. #4

    Default

    thx Animal that makes sense.

    changing my hiddenName field to name effectively solved this.

Posting Permissions

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