1. #1
    Sencha User
    Join Date
    Dec 2008
    Posts
    17
    Answers
    2
    Vote Rating
    0
    dgubber is on a distinguished road

      0  

    Default Answered: Dynamically set combo box value and display

    Answered: Dynamically set combo box value and display


    All,

    I've looked all over for the answer to this and I am getting more and more confused.....

    I am trying to set the value of a combobox when the form is opened, where the combobox's store is already loaded.

    Here is the store definition

    Code:
        var DStore = new Ext.data.Store({
            autoLoad:        true,
            storeId:         'DStore',
            proxy: {
                type:        'ajax',
                url:         '../php/get-listC.php?tp=zones',
                filterParam: undefined,
                groupParam:  undefined,
                limitParam:  undefined,
                pageParam:   undefined,
                sortParam:   undefined,
                startParam:  undefined,
                reader: {
                    type:       'json',
                    root:       'zones',
                    idProperty: 'origin'
                }
            },
            fields: [
                     {name: 'sid'},
                     {name: 'origin'}
                    ]
        });
    Here is the combo box definition in the form

    Code:
            },{
                emptyText:          '- DOMAIN -',
                fieldLabel:         'Domain ',
                xtype:              'combo',
    
                store:              DStore,
                queryParam:         undefined,
                queryMode:          'remote',
                queryCaching:       false,
                listConfig: {
                    // cls:
                    // emptyText:
                    // itemSelector:
                    loadingText:    'Retrieving DOMAINS...',
                    minWidth:       180,
                    maxWidth:       180,
                    maxHeight:      155,
                    // resizable:
                    // shadow:
                    width:          180,
    
                    getInnerTpl: function() {
                        return '<div data-qtip="{origin}">{origin}</div>';
                    }
    
                },
                listAlign:          'bl-tl',
    
                name:               'MSID',
                displayField:       'origin',
                valueField:         'sid',
                hiddenName:         'MSID',
                editable:           false,
                forceSelection:     true,
                triggerAction:      'all',
                allowBlank:         false
    When I open the form and just use the combo box for selection it all works fine. When I attempt to set the combo box value thru a number of different methods I get varying results.....

    Code:
                    var form = frmIPS.getForm();
    
                    form.findField("MVLAN").forceSelection = false;
                    form.findField("PType").forceSelection = false;
                    form.findField("MSID").forceSelection = false;
    
                    // name:               'MSID',
                    // displayField:       'origin',
                    // valueField:         'sid',
                    // hiddenName:         'MSID',
                    // editable:           false,
                    // forceSelection:     true,
                    // triggerAction:      'all',
                    // allowBlank:         false
    
                    form.setValues({
                        HID:            rcd_hid,
                        MVLAN:          rcd_vlan,
                        PType:          rcd_ptype,
                        IPAddress:      rcd_ipaddress,
                        Hostname:       rcd_hostname
                        // MSID:           {rcd_msid, rcd_origin}
                    });
    
                    // var DArray = {};
                    // DArray['sid'] = rcd_msid;
                    // DArray['origin'] = rcd_origin;
    
                    form.setValues({MSID: rcd_msid, 1: 'One'});
    
                    // form.findField("MSID").setValue([rcd_msid, rcd_origin]);
                    // form.findField("MSID").setValue(DArray);
    
                    // form.findField("MSID").setRawValue(rcd_origin);
    
                    form.findField("MVLAN").forceSelection = true;
                    form.findField("PType").forceSelection = true;
                    form.findField("MSID").forceSelection = true;
    One attempt might set the id value in the box, but not the "display" value
    One attempt might set the "id, display" value
    One attempt sets the text, but when submitted does not translate the id

    What I've read indicates that if the store is set to autoload ( which it is ), that if the value is set ( ie, id of 27 ) the display should automatically be set to the equivalent text for that record, but it is not...

    As you can see by the lines that are commented out I've tried a number of different combinations with no luck.

    And help would be appreciated

    Dan

  2. Really????

    I just set the parameter in the store model from int to string and it fixed it!!

    Really !!??


    {name: 'msid', type: 'string'},


    I had the as 'int'

  3. #2
    Sencha User
    Join Date
    Dec 2008
    Posts
    17
    Answers
    2
    Vote Rating
    0
    dgubber is on a distinguished road

      0  

    Default must be a string value !!!!!!!!!!!!!!!!

    must be a string value !!!!!!!!!!!!!!!!


    Really????

    I just set the parameter in the store model from int to string and it fixed it!!

    Really !!??


    {name: 'msid', type: 'string'},


    I had the as 'int'

  4. #3
    Sencha - Support Team
    Join Date
    Feb 2013
    Location
    California
    Posts
    3,095
    Answers
    129
    Vote Rating
    59
    Gary Schlosberg has a spectacular aura about Gary Schlosberg has a spectacular aura about Gary Schlosberg has a spectacular aura about

      0  

    Default


    Glad you found the solution and thanks for sharing it back with the community.
    Are you a Sencha products veteran who has wondered what it might be like to work at Sencha? If so, please reach out to our recruiting manager: sheryl@sencha.com

Thread Participants: 1

Tags for this Thread