2017-06-10 27 views
0

我有一些包含radiogroups的ExtJS表單。Radiobutton沒有被選中,同時以表格形式設置值

而且這些無線電組中的每一個都有2個無線電,其inputValues爲truefalse

但是當我使用form.setValues(values)設置表格值時,如果我想設置的radioButton值是false,那麼相應的收音機沒有被選中。這適用於我的價值是true

這裏是鏈接fiddle

如果你改變booleanRadio: true這工作。

我的代碼:

Ext.define('myView', { 
    extend: 'Ext.panel.Panel', 
    xtype: 'myView', 
    id: 'myViewContainer', 
    layout: 'vbox', 
    width: '100%', 
    initComponent: function() { 
     var me = this; 
     var allItems = []; 
     allItems.push(me.getMyForm()); 
     Ext.applyIf(me, { 
      items: allItems 
     }); 
     me.callParent(arguments); 
    }, 

    getMyForm: function() { 
     var me = this; 
     var currentForm = { 
      xtype: 'form', 
      cls: 'y-form', 
      id: 'myForm', 
      trackResetOnLoad: true, 
      items: [ 
       { 
        xtype: 'radiogroup', 
        fieldLabel: 'is Sponsored', 
        labelSeparator: '', 
        layout: 'hbox', 
        items: [ 
         { 
          xtype: 'radiofield', 
          name: 'isSponsored', 
          boxLabel: 'Yes', 
          inputValue: true 
         }, 
         { 
          xtype: 'radiofield', 
          name: 'isSponsored', 
          boxLabel: 'No', 
          inputValue: false 
         } 
        ] 
       } 
      ] 
     }; 

     return currentForm; 
    } 
}); 

Ext.define('myController', { 
    extend: 'Ext.app.Controller', 
    init: function() { 
     this.control({ 
      'panel#myViewContainer': { 
       afterrender: this.retrieveFormValues 
      } 
     }); 
    }, 

    retrieveFormValues: function() { 
     var me = this; 
     var data = {isSponsored: false}; 
     if (data != null && !Ext.Object.isEmpty(data)) { 
      var myFormContainer = Ext.getCmp('myViewContainer'); 
      myFormContainer.getForm().setValues(data); 
     } 
    } 
}); 
+0

添加我的代碼..我之前沒有添加它,因爲它很複雜。簡化後我添加了。 – Harshal

+0

我已經報告了一個與Sencha非常相似的問題,它被追蹤爲EXTJS-25448;除了可以將布爾值轉換爲字符串並將這些字符串值用作收音機的'inputValue'外,現在沒有可用的解決方法。 – Alexander

+0

我覺得這看起來像ExtJS Bug。 這不是一個解決方案。這只是解決方法。 var values = { booleanRadio:result? 1:0; }; –

回答

0
如果更改單選按鈕的inputValues爲0或1,和調整值

VAR相應地,所需的單選按鈕將被設置。我已經更新了小提琴。

items: [{ 
    boxLabel: 'Item 1', 
    name: 'booleanRadio', 
    inputValue: 1, 
    }, { 
    boxLabel: 'Item 2', 
    name: 'booleanRadio', 
    inputValue: 0, 
    }], 
    listeners: { 
    afterrender: function(radioGroupForm) { 

     var values = { 
     booleanRadio: 0 
     } 
     Ext.getCmp('radioGroupFormPanel').getForm().setValues(values); 
    } 
    } 

如果您發送虛假至單選按鈕,它取消選中收音機。這就是爲什麼你的'真'是工作,'假'不是。

相關問題