2
$\begingroup$

I created three interdependent PopupMenus with names demographic, region and custom:

DynamicModule[{demographic = "Demographic", region = "Region", custom = "Custom"},
 Dynamic@Grid@{{
     PopupMenu[Dynamic[demographic], {"Demo1", "Demo2", "Demo3"}, "Demographic"],
     PopupMenu[Dynamic[region], {"Region1", "Region2", "Region3"}, "Region"],
     PopupMenu[Dynamic[custom], {"Custom1", "Custom2", "Custom3"}, "Custom"]
     }}]

enter image description here

These controls should depend on each others' values. I want the followings:

  1. region and demographic should be reset to "Region" and "Demographic" if any from custom is selected

  2. custom should be reset to "Custom" if either demographic or region is changed

I tried it with If and Which but it still won't work. How can I control these three PopupMenus?

$\endgroup$
3
  • 1
    $\begingroup$ It is always a good idea to try to make your code samples that show the behaviour in question, as short as you can. $\endgroup$
    – Rojo
    Dec 11, 2012 at 18:46
  • $\begingroup$ I think you will probably find answers to similar problems have already been posted here ...but most likely this can be done within the second argument to Dynamic $\endgroup$ Dec 11, 2012 at 20:59
  • $\begingroup$ @Subbu I've greatly simplified your question: most of it was just styling and sugar. You would get much faster and better answers if you were to put more effort into disassembling your problems to the core. In this case, it could even have been reduced to a two-interrelated-controller problem using the second argument of Dynamic of which here and here are a few answers. (yes I am aware of the date) $\endgroup$ Apr 9, 2013 at 12:31

1 Answer 1

3
$\begingroup$

You have to use the second argument of Dynamic. Any function put there will be evaluated whenever the controller is changed, so it is quite straightforward to include the resetting of the other popup menus:

DynamicModule[{demographic = "Demographic", region = "Region", custom = "Custom"},
 Dynamic@Grid@{{
   PopupMenu[
     Dynamic[demographic, (demographic = #; custom = "Custom") &],
     {"Demo1", "Demo2", "Demo3"}, "Demographic"],
   PopupMenu[
     Dynamic[region, (region = #; custom = "Custom") &],
     {"Region1", "Region2", "Region3"}, "Region"],
   PopupMenu[
     Dynamic[custom, (custom = #; demographic = "Demographic"; region = "Region") &], 
     {"Custom1", "Custom2", "Custom3"}, "Custom"]
     }}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.