I'm using RoR with simple_form and cocoon to handle this structure : Node has_many :addresses
Each Address has a boolean :main field which will flag one of each Node address as the main one (actually the one used for SNMP monitoring).
I've a nested form to manage these addresses but I can't find a clean way to select the main one.
Logically, I should use a radio buttons group, each address being one radio group option, but, in a nested form, each radio button will belong to one single address and have a different name, meaning they're in different groups.
I could link the radio button input to a virtual attribute in Node, and set selected address':main field to true in a callback, but how will I link each button to its address (I could use address ID as button value, but newly added addresses have no ID yet).
Here's a simplified version of what my Node form should look like (parentheses represent radio buttons, brackets for text inputs) :
Name : [MyNode1 ]
| Address | Main |
|------------|------|
| [10.0.0.1] | (*) |
| [10.0.0.2] | ( ) |
| [10.0.0.3] | ( ) |
My only other solution would be a JS feeded selectbox (options updated when I change something in addresses list) but it's definitely less clean and logical than a simple radio group...
Edit
An "acceptable" workaround would be to group radio buttons on something else than name attribute (example : data-group attribute). Does someone know any good JS/jQuery plug-in that could do this ?