English 中文(简体)
外部可用/可处置的检查箱
原标题:Enable/disable checkbox in extjs

I want to enable or disable checkboxes in EXTJS

 dockedItems: [{
        xtype:  toolbar ,
        dock:  top ,
        items: [{
            xtype:  radiofield ,
            id:  all ,
            name:  show ,
            boxLabel:  All ,
            checked: true,
            inputValue:  all 
        }, {
            xtype:  radiofield ,
            id:  online ,
            name:  show ,
            boxLabel:  Online ,
            inputValue:  online 
        }, {
            xtype:  radiofield ,
            id:  offline ,
            name:  show ,
            boxLabel:  Offline ,
            inputValue:  offline 
        }, {
            xtype:  checkboxfield ,
            id:  cb1 ,
            boxLabel:  Sometimes ,
            checked: true,
            inputValue:  sometimes 
        }, {
            xtype:  checkboxfield ,
            id:  cb2 ,
            boxLabel:  Always ,
            checked: true,
            inputValue:  always 
        }],
        listeners: {
            change: function (field, newValue, oldValue) {
                var value = newValue.show;
                if (value ==  all ) {
                    var cb1 = Ext.getCmp( cb1 );
                    var cb2 = Ext.getCmp( cb2 );

                    cb1.disable();
                    cb2.disable();
                }
                if (value ==  online ) {
                    var cb1 = Ext.getCmp( cb1 );
                    var cb2 = Ext.getCmp( cb2 );

                    cb1.disable();
                    cb2.disable();
                }
                if (value ==  offline ) {

                    var cb1 = Ext.getCmp( cb1 );
                    var cb2 = Ext.getCmp( cb2 );

                    cb1.enable();
                    cb2.enable();

                }

            }
        }
    }]

How can I enable these checkboxes? They should be enabled when the user selects the offline option and disabled when the user selects other option.

感谢你们的帮助!

最佳回答

A couple errors I noticed:

The checkbox components cant be referred to by their id directly, you could call them with Ext.getCmp( id ) though.

Your listener in the example above is attached to the toolbar, which doesn t have a change event. You need to attach it to the radio instead.

实际上,如果你只想在离线无线电台填满时能够使用的检查箱,那么我会建议在离线无线电台上添加一个<代码>handler,功能是使检查箱能够或消除,取决于该无线电台的价值变化。 例如,这项工作:

dockedItems: [{
    xtype:  toolbar ,
    dock:  top ,
    items: [{
        xtype:  radiofield ,
        id:  all ,
        name:  show ,
        boxLabel:  All ,
        checked: true,
    }, {
        xtype:  radiofield ,
        id:  online ,
        name:  show ,
        boxLabel:  Online ,
        inputValue:  online ,
    }, {
        xtype:  radiofield ,
        id:  offline ,
        name:  show ,
        boxLabel:  Offline ,
        inputValue:  offline ,
        handler: function(field, value) {
            if (value) {
                Ext.getCmp( cb1 ).enable();
                Ext.getCmp( cb2 ).enable();
            } else {
                Ext.getCmp( cb1 ).disable();
                Ext.getCmp( cb2 ).disable();        
            }            
        }
    }, {
        xtype:  checkboxfield ,
        id:  cb1 ,
        boxLabel:  Sometimes ,
        checked: true,
        inputValue:  sometimes ,
        disabled: true
    }, {
        xtype:  checkboxfield ,
        id:  cb2 ,
        boxLabel:  Always ,
        checked: true,
        inputValue:  always ,
        disabled: true
    }]
}],

I suggest using handler config (as above) and not having a listener on the change event.

If you add a change listener it will override the default change handler used by ExtJS internally to deselect the other radio fields in the same name group. E.g. with a change listener on the offline radio, when you select it, all will remain selected.

In other words... just copy the example above and all will be well.

问题回答

你们可以做以下工作,为检查箱打上ids子,以树立榜样:

 if (value ==  offline ) {
            var cb1 = Ext.getCmp( cbox1 );//look up by given checkbox ids
            var cb2 = Ext.getCmp( cbox2 );//look up by given checkbox ids

cb1.enable();
cb2.enable(); 

online 
  }
else {
        var cb1 = Ext.getCmp( cbox1 );//look up by given checkbox ids
            var cb2 = Ext.getCmp( cbox2 );//look up by given checkbox ids

cb1.disable();
cb2.disable(); 
}

A standard approach to enable / disable checkbox in ExtJS is to set configuration parameters disable: true or disable: false when creating component.

但是,就ExtJS 4.2而言,它有些不便。 拆卸或设置仅读的检查箱,使部分看得非常透明。 在传统的框架设计中,可能有些则在盒子中打折或On读。 如果是空的。

我们找到的最佳解决办法是,为这种类型的所有外部司法调查要素建立一个全球项目组。 它转向标准框架主题形象中更好的标志,并增加一些不透明之处:

.x-form-readonly .x-form-checkbox {
  background-image: url(/extjs/resources/ext-theme-classic/images/form/checkbox.gif);
  opacity: 0.4;
}




相关问题
ExtJS load form items/fields from database

I am using ExtJS 3 here. I would like to populate a formpanel from database with fields to be submitted. Basically, I don t know witch fields my form will have and I want to generate all formpanel ...

How to use Ext JS for role based application

I am planning to use Ext JS for a large application. The application s features are role based. When user login, they only see menu and screen features related to them. My server side technology will ...

Dynamically adding a TabPanel to a Panel Region

I have a Panel layout with a TreePanel in one region. A user clicks on an node in the tree and a TabPanel should be displayed in another region with information, editing tools etc. for that tree node....

How to embed Json result within Extjs Panel?

I have some issues with Json result and embed it within the html of the Extjs Panel. Here s that I have managed to get so far. myPanel is embedded within a mainPanel, and I have some shows/hide of ...

Ajax data update. Extjs

I need to keep certain data ( in a grid) up to date and was gonna do a poll to the server every 15 seocnds or so to get the data and refresh the grid, however it feels a bit dirty ( the grid will have ...

Better way to call superclass method in ExtJS

All the ExtJS documentation and examples I have read suggest calling superclass methods like this: MyApp.MyPanel = Ext.extend(Ext.Panel, { initComponent: function() { // do something MyPanel ...

Merged Headers in Ext JS Grid

Is it possible to have two headers in Ext JS grids? I have to show my grid as grouped data.. for example product types and products. In my case I need a grid like this: Field | Product Type A ...

热门标签