5
$\begingroup$

Code fragments below

buildDateChoices[datenums : {{_Integer, _Integer, _Integer} ..}] :=GroupBy[datenums, {First -> Rest, First -> Last}]

getMonthsX[y_Integer] := Keys@Lookup[datechoiceset, y, {1}];

getDaysX[y_Integer, m_Integer] := Lookup[datechoiceset, y, Range[12]][m];

testdatelist = Sort[{RandomInteger[{2008, 2015}, 25], RandomInteger[{1, 12}, 25], RandomInteger[{1, 30}, 25]}\[Transpose]];

datechoiceset = buildDateChoices[testdatelist]

<|2008-><|1->{15},3->{11},6->{15},10->{1},11->{9},12->{1}|>,2009-><|1->{24},6->{25},7->{29},11->{25}|>,2010-><|2->{13},3->{19},4->{29},6->{3},7->{26,27,29},9->{23},10->{13},11->{15}|>,2011-><|2->{14},3->{17}|>,2012-><|1->{8},4->{30},6->{24},9->{5},10->{15},12->{15}|>,2013-><|11->{8}|>,2014-><|1->{5,17},2->{26},4->{21},6->{19},7->{5,13},9->{21},10->{14}|>,2015-><|2->{5},5->{19,29},10->{5,29},11->{15},12->{28}|>|>

The individual getMonthsX, getDayX function work. But the code below does not.

DialogInput[DynamicModule[{cyear, cmonth, cday, yearlist},  
  yearlist = Keys@datechoiceset;
  getMonths[y_Integer] := Keys@Lookup[datechoiceset, y, {1}];  
  getDays[y_Integer, m_Integer] := Lookup[Lookup[datechoiceset, y, Range[12]], m, Range[30]];   
  Column[{TextCell[Style["Choose a File Date ", Blue, Bold, 16]],  
    TextCell[" "],  
    Row[{"Year: ", PopupMenu[Dynamic[cyear], yearlist],       "   Month: ",  
        PopupMenu[Dynamic[cmonth], Dynamic@getMonths[cyear]],"   Day: ",   
        PopupMenu[Dynamic[cday], Dynamic@getDays[cyear, cmonth]]}],TextCell[" "],  
    Row[{Button["  Select  ", DialogReturn[{cyear, cmonth, cday}]], "    ",  
    CancelButton[]}]  
}]]]

I have looked at several related examples on Stack Exchange including Date Picker, I have also tried using the second argument of Dynamic to set the lists, without success. Any help you could provide would be welcome.

$\endgroup$
2
  • $\begingroup$ You should replace numdates with 25 $\endgroup$
    – eldo
    Commented Nov 7, 2015 at 20:27
  • $\begingroup$ Yes, it was a variable in the live code. Not the source of the problem. $\endgroup$
    – John McGee
    Commented Nov 7, 2015 at 20:37

1 Answer 1

7
$\begingroup$

A simple example of one popup depending on the selection of another:

DynamicModule[{x, y, list},

 {PopupMenu[
   Dynamic[x, (x = #; 
      list = Switch[#, "A", {1, 2, 3}, "B", {4, 5, 6}, 
        "C", {7, 8, 9}]; y = First[list]) &], {"A", "B", "C"}],

  Dynamic[PopupMenu[Dynamic[y], list], TrackedSymbols :> {list}]}
 ]

enter image description here

$\endgroup$
2
  • $\begingroup$ TrackedSymbols is the key? $\endgroup$
    – John McGee
    Commented Nov 8, 2015 at 11:16
  • $\begingroup$ @JohnMcGee I've used TrackedSymbols because you only want the second popup to change when list has changed. $\endgroup$ Commented Nov 8, 2015 at 21:48

Your Answer

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

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