2017-06-10 26 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); 
    } 
    } 

如果您发送虚假至单选按钮,它取消选中收音机。这就是为什么你的'真'是工作,'假'不是。

相关问题