Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem loading extjs radiogroup data

How do you load data for a radiogroup in extjs, such that the correct radios are checked?

On the extjs radio/checkbox example page you will find code like this

{
  xtype: 'radiogroup',
  fieldLabel: 'Auto Layout',
  items: [
       {boxLabel: 'Item 1', name: 'rb-auto', inputValue: 1},
       {boxLabel: 'Item 2', name: 'rb-auto', inputValue: 2, checked: true},
       {boxLabel: 'Item 3', name: 'rb-auto', inputValue: 3},
       {boxLabel: 'Item 4', name: 'rb-auto', inputValue: 4},
       {boxLabel: 'Item 5', name: 'rb-auto', inputValue: 5}
   ]
 }

I would expect that doing a form.load() with json like {'rb-auto': 3, …} would mark Item 3 as checked. This doesn't work. How could you achieve this effect?

Answer: (Zach is correct about extjs 3.1) My expectation is correct, but only since extjs 3.1 is released recently. Also, you need to set the name on boh the individual radio items as the group itself:

{
  xtype: 'radiogroup',
  fieldLabel: 'Auto Layout',
  name: 'rb-auto',
  items: [
       {boxLabel: 'Item 1', name: 'rb-auto', inputValue: 1},
       {boxLabel: 'Item 2', name: 'rb-auto', inputValue: 2, checked: true},
       {boxLabel: 'Item 3', name: 'rb-auto', inputValue: 3},
       {boxLabel: 'Item 4', name: 'rb-auto', inputValue: 4},
       {boxLabel: 'Item 5', name: 'rb-auto', inputValue: 5}
   ]
 }
like image 619
Exception e Avatar asked Dec 09 '25 22:12

Exception e


2 Answers

Using ExtJS 4, the following structure for radio group settings resulting in success for me:

{ "data" : 
    [ 
      { "id" : "RadioGroupName",
        "value" : 
            { "RadioGroupName" : "inputValue" }
      },
      { "id" : "RadioGroupName2",
        "value" : 
            { "RadioGroupName2" : "inputValue" }
      }
    ],
  "success" : true
}
like image 117
Eric Betts Avatar answered Dec 12 '25 12:12

Eric Betts


This was a solution that was working for extjs 3.0: http://www.extjs.com/forum/showthread.php?t=39161

With 3.1 it doesn't work. :-(

like image 41
stach Avatar answered Dec 12 '25 12:12

stach