I want to create two RadioButtonBar
objects that offer choices which are dynamically updated by a CheckboxBar
. I also need to prevent them from having the same value. I got this far.
My Problem : When the currently selected button of a RadioButtonBar
has its value updated through the CheckboxBar
, it becomes de-selected. In other words, the value of the RadioButtonBar
is updated, but not the value of the variable controlled by it.
I provide a toy example here, but in my real situation, I have many more dynamic lists and buttons. Hence, I'm looking for a solution that doesn't require each dList
or dRadio
to perform a long list of checks to determine what needs to be updated.
DynamicModule[{dList1 = {a}, dList2 = {d}, dList3 = {g}, dRadio1, dRadio2},
dRadio1=dList1;
dRadio2=dList2;
Grid[{
{"List 1:", CheckboxBar[Dynamic[dList1], {a, b, c}]},
{"List 2:", CheckboxBar[Dynamic[dList2], {d, e, f}]},
{"List 3:", CheckboxBar[Dynamic[dList3], {g, h, i}]},
{"Radio 1:", Dynamic[RadioButtonBar[
Dynamic[dRadio1, {(If[# == dRadio2, dRadio2 = dRadio1]) &, Automatic}],
{dList1, dList2, dList3}]]},
{"Radio 2:", Dynamic[RadioButtonBar[
Dynamic[dRadio2, {(If[# == dRadio1, dRadio1 = dRadio2]) &, Automatic}],
{dList1, dList2, dList3}]]},
{Dynamic[dRadio1]},
{Dynamic[dRadio2]}}]]
{a}
selected. If you change dList1 to be{a,b}
through the CheckboxBar, the value of the RadioButtonBar should update (as it does) and the first choice should still be selected. EDITED TO REFLECT CODE CHANGE. $\endgroup$RadioButtonBars
? What about thosedRadio1
anddRadio2
do they need to also update? What would they update to? $\endgroup$dRadio1 = dList1
anddList1
changes,dRadio1
should update so thatdRadio1 = dList1
. $\endgroup$