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.
Answer
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}]}
]
Comments
Post a Comment