views:

1722

answers:

1

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}
   ]
 }
+1  A: 

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. :-(

stach
Ok. It seems to me that giving a "name" attribute to radiogroup solves this problem.
stach
Thanks. Which solution do you mean? This thread contains lots of code, which one did you find the most correct? A shame that we need to hack ourselves around the flaws in extjs.
Exception e
The one from the last page of the thread.Yes, it was a big flaw and it seems to be corrected right now in extjs 3.1. I just had to find out that it needs the name attr on radiogroup itself apart from naming each radios individually.Generally speaking - extjs is a great idea but the implementation is poor and undocumented.
stach
Thanks for your comment. It feds out that both the group as the individual items needs to share the same name.
Exception e