2012-05-23 25 views
3

我在extJS 4中使用xtype在FormPanel內創建radioGroup。我試圖在收音機被選中時啓用/禁用文本字段。Ext JS 4收音機組檢查事件

{ 
xtype: 'radiogroup', 
fieldLabel: 'Enable/Disable ', 
columns: 2, 
vertical: true, 
items: [ 
    {boxLabel: 'Enable', name: 'formtype', inputValue: '1'}, 
    {boxLabel: 'Disable', name: 'formtype', inputValue:'2',checked:true}, 
    ] 
} 

我很困惑爲檢查/點擊事件添加監聽器的位置。預先感謝一噸。

+0

我試圖添加這種方式,但爲什麼它顯示alert()2次? – aswininayak

+1

聽衆:{ \t「change」:function(field,newValue,oldValue,eOpts){ \t \t alert(this.items); } \t \t \t \t \t} – aswininayak

回答

11

您必須在每個單選按鈕上處理「更改」事件。當一個單選按鈕改變(選中),然後啓用/禁用文本框。

下面的例子:

Ext.create ('Ext.container.Container', { 
    renderTo: Ext.getBody() , 
    items: [{ 
     xtype: 'textfield' , 
     id: 'tf' , 
     disabled: true , 
     fieldLabel: 'My Text' 
    } , { 
     xtype: 'radiogroup', 
     fieldLabel: 'Enable/Disable ', 
     columns: 2, 
     vertical: true, 
     items: [{ 
      boxLabel: 'Enable', 
      name: 'formtype' , 
      inputValue: '1' , 
      listeners: { 
       change: function (cb, nv, ov) { 
        if (nv) Ext.getCmp('tf').enable(); 
       } 
      } 
     } , { 
      boxLabel: 'Disable', 
      name: 'formtype', 
      inputValue:'2', 
      checked: true , 
      listeners: { 
       change: function (cb, nv, ov) { 
        if (nv) Ext.getCmp('tf').disable(); 
       } 
      } 
     }] 
    }] 
}); 

+1

由於威爾克它的工作.... – aswininayak

2

如果設置無線電集團本身(而不是在每個按鈕上)監聽變化事件,你將只需要處理一個事件。您的聽衆/處理程序將被調用並通過newValoldVal。然後,您可以抓取newVal作爲選定的值。