I am working on a dashboard with four UDSelect elements. They each carry the same list of items, about half a dozen apps to choose from. I’m attempting to configure the four elements in a dynamic fashion so that if the user selects an application from any one of them, that choice is removed from the others (e.g. I select Outlook on dropdown 1 and Web App on dropdown 2, and those choices are removed from dropdowns 3 and 4).
I know I am getting the syntax wrong, just not sure how best to do this. In the sample below, I am confirming the selection chosen is removed from the array, but it does not seem to be updating the other elements. If anyone has done this with multiple elements updating each other dynamically, or could point me in the right direction, I would appreciate it.
New-UDDashboard -Title 'Home' -Content {
$aApps = @(
"Select",
"Email",
"Spreadsheets (Excel, Google Sheets, etc.)",
"Web Page or Application",
"PDF",
"Locally Installed Application",
"API",
"Database (Oracle, SQL, etc.)"
)
New-UDDynamic -Id "dynSource1" -Content {
New-UDSelect -Id "cmbDataSource1" -Label "Data Source 1" -FullWidth -DefaultValue "Select" -Option {
foreach ($app in $aApps) {
New-UDSelectOption -Name $app -Value $app
}
} -OnChange {
$selection = (Get-UDElement -Id "cmbDataSource1").Value
$aApps = $aApps | ? {$_ -ne $selection}
foreach ($element in $aApps) {
Show-UDToast -Message $element -Duration 3000
}
Sync-UDElement -Id "dynSource2"
Sync-UDElement -Id "dynSource3"
Sync-UDElement -Id "dynSource4"
}
}
New-UDDynamic -Id "dynSource2" -Content {
New-UDSelect -Id "cmbDataSource2" -Label "Data Source 2" -FullWidth -DefaultValue "Select" -Option {
foreach ($app in $aApps) {
New-UDSelectOption -Name $app -Value $app
}
} -OnChange {
$selection = (Get-UDElement -Id "cmbDataSource2").Value
$aApps = $aApps | ? {$_ -ne $selection}
Sync-UDElement -Id "cmbDataSource1"
Sync-UDElement -Id "cmbDataSource3"
Sync-UDElement -Id "cmbDataSource4"
}
}
New-UDDynamic -Id "dynSource3" -Content {
New-UDSelect -Id "cmbDataSource3" -Label "Data Source 3" -FullWidth -DefaultValue "Select" -Option {
foreach ($app in $aApps) {
New-UDSelectOption -Name $app -Value $app
}
} -OnChange {
$selection = (Get-UDElement -Id "cmbDataSource3").Value
$aApps = $aApps | ? {$_ -ne $selection}
Sync-UDElement -Id "cmbDataSource1"
Sync-UDElement -Id "cmbDataSource2"
Sync-UDElement -Id "cmbDataSource4"
}
}
New-UDDynamic -Id "dynSource4" -Content {
New-UDSelect -Id "cmbDataSource4" -Label "Data Source 4" -FullWidth -DefaultValue "Select" -Option {
foreach ($app in $aApps) {
New-UDSelectOption -Name $app -Value $app
}
} -OnChange {
$selection = (Get-UDElement -Id "cmbDataSource4").Value
$aApps = $aApps | ? {$_ -ne $selection}
Sync-UDElement -Id "cmbDataSource1"
Sync-UDElement -Id "cmbDataSource2"
Sync-UDElement -Id "cmbDataSource3"
}
}
}
Product: PowerShell Universal
Version: 3.2.6