1. #1
    Sencha User
    Join Date
    Mar 2008
    Posts
    55
    Vote Rating
    10
    andong will become famous soon enough

      0  

    Default [4.1.1 RC1] Combo field was not selected with form.loadRecord() method

    [4.1.1 RC1] Combo field was not selected with form.loadRecord() method


    Here is the combo field:

    Code:
    {
        fieldLabel: 'Gender',
        xtype: 'combo',
        name: 'gender',
        allowBlank: false,
        valueField: 'id',
        displayField: 'value',
        editable: false,
        queryMode: 'local',
        triggerAction: 'all',
        store: Ext.create('Ext.data.ArrayStore', {
            fields: ['id', 'value'],
            data: [['1', 'Male'], ['2', 'Female']]
        }),
        value: '1'
    }
    At the first time, I will open a window to show the add form and the combo correctly selects the Male option by configuration. But when I open edit window and use the form.loadRecord() method to populate the form's fields, all are populated correctly except the combo fields, all the combo fields's text are the id value (For Gender field is 1) and not select the wanted one.

    I also try to use this code to force select the option but failed
    Code:
    form.findField('gender').setValue(user.get('gender'));
    Any suggestions?
    Last edited by skirtle; 25 May 2012 at 1:47 AM. Reason: Edit to make code readable

  2. #2
    Sencha User
    Join Date
    Mar 2008
    Posts
    55
    Vote Rating
    10
    andong will become famous soon enough

      0  

    Default


    Anybody here?

  3. #3
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,624
    Vote Rating
    331
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    I suspect it's a type mismatch.

    This works as expected:

    Code:
    combo.setValue('2');
    This works the way you describe:

    Code:
    combo.setValue(2);
    It's the same against 4.1.0.

  4. #4
    Sencha User
    Join Date
    Mar 2008
    Posts
    55
    Vote Rating
    10
    andong will become famous soon enough

      0  

    Default


    Quote Originally Posted by skirtle View Post
    I suspect it's a type mismatch.

    This works as expected:

    Code:
    combo.setValue('2');
    This works the way you describe:

    Code:
    combo.setValue(2);
    It's the same against 4.1.0.
    Thanks.
    Yes, it's a data format issue - the value is int in the model. I changed the codes like below and it works

    Code:
    {
        fieldLabel: 'Gender',
        xtype: 'combo',
        name: 'gender',
        allowBlank: false,
        valueField: 'id',
        displayField: 'value',
        editable: false,
        queryMode: 'local',
        triggerAction: 'all',
        store: Ext.create('Ext.data.ArrayStore', {
            fields: ['id', 'value'],
            data: [[1, 'Male'], [2, 'Female']]
        }),
        value: 1
    }

  5. #5
    Sencha User
    Join Date
    Mar 2008
    Posts
    55
    Vote Rating
    10
    andong will become famous soon enough

      0  

    Default


    BTW, It won't need to call setValue method, just call form.loadRecord method is enough.

Thread Participants: 1