Consider the following code, where I have a list of variables, each with different specified units. In my real case, these lists are not fixed, hence the surrounding Dynamic and the general definition for selected. I have checkboxes associated with each, but I only want to allow checkboxes to be simultaneously selected if the variables have the same units. So if, for example, I have "a" selected, but then select "b", that is allowed. But if I have "a" and/or "b" selected, and try to select "c", I want "a" and "b" to become deselected in the process. How can I accomplish this?
Module[{vars = {a, b, c, d},
varunits = {"Molar", "Molar", "Seconds", "DimensionlessUnit"},
selected},
selected[index_] = False;
Deploy[Dynamic[Column[
Row[{vars[[#]], " ",
Checkbox[Dynamic[selected[#]]], " ",
varunits[[#]]}] & /@ Range[Length[vars]]]]]]
Edited to add: It looks like I can do this using the second parameter of “Dynamic.” But that raises a secondary question: suppose this checkbox is already part of a pure function with slots. The second parameter of Dynamic needs to also be a pure function. And I would like to pass it parameters from the outer slots. Can that be done?