Populate dropdown list dynamically

In my dashboard, I need to have a drop down list that is populated with items that would be files in the directory the dashboard is in. The files are .json files that I’d like to have the data loaded on selection but I am not sure how to go about populating the list without using validate set and I don’t think that will work.

Something like this?

$files = get-childitem "\path goes here\*.json"

New-UDSelect -Option {

    foreach($file in $files){

        New-UDSelectOption -Name $file.basename -Value $file.basename


} -OnChange {

   show-udtoast -message $EventData


That get’s me started. Thank you!