Extjs radiogroup fieldLabel not displaying inside panel

瘦欲@ 提交于 2019-12-13 06:04:05

问题


I am using ExtJs 2.3.0.

I have a panel and inside it a radiogroup as follows

var testPanel = {
          xtype: 'panel',  
          border: false,
          items: [ 
                    { fieldLabel: 'Please select ', 
                      xtype: 'radiogroup', 
                      id: 'id1', 
                      columns: 2, 
                      vertical: false
                    }
                 ],
                 items: [
                            { boxLabel: 'Yes', name: 'yes', inputValue: 'Yes', xtype: 'radio'},
                            { boxLabel: 'No', name: 'no', inputValue: 'No', xtype: 'radio' }
                        ]
         }

The issue is-
The fieldLabel 'Please select' of radioBox is not displaying. I am able to see 'Yes'/ 'No' radiobuttons.

When I change xtype of testPanel to 'form', the label displays. However, I can't use 'form' xtype. I want to use 'Panel' only.

Please let me know why the fieldLabel is not diaplying inside panel and any workaround for this.


回答1:


For one thing, the individual radio buttons must be items of the radio group. Here, you've got the items keys that is duplicated in your config object, meaning you actually end up with 2 radios in your panel, but no radio group.

Then, simple panels do not have support for displaying labels. You must use a form panel for that.

Finally, you probably want to give all the radio in the group the same name, so that myForm.getForm().getValues() returns something like {myField: "Yes"} (the value will be taken from inputValue).

So here's what you're trying to do:

Ext.ComponentMgr.create({
    xtype: 'form', // notice the changed xtype
    renderTo: Ext.getBody(),
    border: false,
    items: [{
        fieldLabel: 'Please select ',
        xtype: 'radiogroup',
        id: 'id1',
        columns: 2,
        vertical: false,
        // radio buttons must be children of the radio group
        items: [{
            boxLabel: 'Yes',
            // you probably want to give your radios the same name
            name: 'myField',
            inputValue: 'Yes'
        }, {
            boxLabel: 'No',
            name: 'myField',
            inputValue: 'No'
        }]
    }]
});


来源:https://stackoverflow.com/questions/21084941/extjs-radiogroup-fieldlabel-not-displaying-inside-panel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!