1. #1
    Ext User
    Join Date
    Jul 2008
    Posts
    36
    Vote Rating
    0
    michele.segata is on a distinguished road

      0  

    Default ComboBox setting value by id

    ComboBox setting value by id


    Hi,
    i was searching in the documentation a method to set the combobox value by the field id.
    for example, if i have:

    [{id:1, value:'hi'}, {id:2, value:'bye'}]

    what i want to do is something like that:

    ComboBox.setValue(2); note that the displayField is 'value'

    I was unable to find a method to do this and a topic in the forum
    Thank you

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,506
    Vote Rating
    54
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    setValue already works like that for ComboBox.

    Obviously, its Store must be loaded so that it can look up the ID, and set the correct value in the display area.

  3. #3
    Ext User
    Join Date
    Jul 2008
    Posts
    36
    Vote Rating
    0
    michele.segata is on a distinguished road

      0  

    Default


    Code:
                    var storeEmployees = new Ext.data.JsonStore({
                        url         : 'stores/employees.php',
                        autoLoad    : true,
                        root        : 'employees',
                        fields      : ['id', 'employee']
                    });
                    var cmbEmployee = new Ext.form.ComboBox({
                        store           : storeEmployees,
                        fieldLabel      : lang.ASSIGNED_TO,
                        editable        : false,
                        triggerAction   : 'all',
                        mode            : 'local',
                        anchor          : '-20',
                        displayField    : 'employee',
                        valueField      : 'id',
                        hiddenName      : lang.FORM_EMPLOYEE,
                        disabledClass   : 'disabledTextField'
                    });
    so... which is the problem in this code? if i try to call cmbEmployee.setValue(1); in the combo i find '1' and not the corresponding value. Where am i wrong?
    thanks

  4. #4
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,506
    Vote Rating
    54
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    It's not loaded, so there are no records in the Store to find id = 1

  5. #5
    Ext User
    Join Date
    Jul 2008
    Posts
    36
    Vote Rating
    0
    michele.segata is on a distinguished road

      0  

    Default


    ok, understood. so i need to wait that the store have finished loading data from the php page. i will use the 'load' listener.
    thank you for your help

Thread Participants: 1