开发者

Extjs comb wont get initial value, only display

I have a form with combo (hiddenName como). The form loads its data from the server and sets the "selectedValue" automatically. The combo loads its value from the server before the form loads its data. If I click on submit, the displayValue will be sent to the server instead of the value even though I set the hiddenName. But if I change the combo value, from then on it will submit the value and not the displayValue, as expected. Why does the initial value that was set by the form prevent the combo from submitting its value?

This is the combo and the store:

var store = new Ext.data.JsonStore({
        autoLoad: true,
        url: config.url,
        root: 'data',
        methos:'POST',
        fields:[{name:'userManager_employeeId'},{name:'userManager_userName'}] });

    var combo  = new Ext.form.ComboBox({
        hiddenName:'userManager',
        valueField: 'userManager_employeeId',
        displayField: 'userManager_userName',
        forceSelection: true,
        mode: 'remote',    
        typeAhead: true,
        lazyInit :false,
        lazyRender:false,
        fieldLabel:     config.title,
        emptyText:'Select a value',
      开发者_如何学C  roles:config.roles,

EDIT

This is the form data:

{
    "data": [
        {
            "employee_employeeId": 3,
            "Affiliate_affiliateId": 8,
            "parent_affiliateId": 8,
            "userManager_employeeId": 1,
            "Affiliate_email": "avi@finexo.co.il",
            "parent_name": "First Affiliate",
            "userManager": "admin",
            "Affiliate_name": "First Affiliate",
            "user_userName": "admin",
            "user_userId": 1
        }
    ]
}

This is the combo data:

{
    "data": [
        {
            "userManager_userName": "admin",
            "userManager_employeeId": 1
        },
        {
            "userManager_userName": "admin2",
            "userManager_employeeId": 4
        }
    ]
}

This is the form reader:

    reader: new Ext.data.JsonReader({
            root: 'data',
            fields: [{
                name: 'userManager'
            }]
        })

This is the form data:

{"data":[{"userManager":"admin"}]}

I also tried:

{"data":[{"userManager":"1"}]}

If the form data is "admin", I see in the display 'admin' but the submitted value is also 'admin'. If the form data is "1", I see in the display "1" and in the submit value "1". How can i see in the display 'admin' and submit the value ("1")? Thanks.


I've run into this issue enough that I've got a plugin that I include on forms with combos. In your case you need to turn off autoload on your combo's store. Populate your form with the combo's valueField, like the second example you've provided. Then modify your server side code to search for valueFields or displayFields, instead of just displayFields. Then you can do this once your form's loaded:

combo.getStore().load({
   params: { query: combo.getValue()},
   callback: function () { combo.setValue(combo.getValue()) }
});

This will send a request to the server just for id 1, and the server will reply with the data for the combo to fix its displayField. setValue then sets the displayField and valueField. It's a workaround, but it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜