How to initialize PopupMenu with first element on each dynamic update?

I wrote a function, which lists directories, which may contain “model” files in the following format

{dirpath1->dirname1, dirpath2->dirname2, ...

i.e. in format, suitable for PopupMenu function.

Then I wrote a function, which lists model files in given directory in the same way

{filepath1->filename1, filepath2->filename2, …

I was wishing to select directory in first popup and then select file in second popup and wrote

PopupMenu[Dynamic[dir], GetModelDirectories[]]

Dynamic[PopupMenu[Dynamic[fil], GetMatFiles[dir]]]

It worked, but partially: if I change first popup, second popup turns empty

8zK1G How to initialize PopupMenu with first element on each dynamic update?

and I need explicitly select second popup

Ozr9j How to initialize PopupMenu with first element on each dynamic update?

Is it possible to initialize second popup automatically to the first item in the list?

Let’s block ads! (Why?)

Recent Questions – Mathematica Stack Exchange