Product: PowerShell Universal
Version: 4.2.3
I have the below code that creates 3 selects dynamically and should enable them after the previous has a value selected:
## Category Selection 1 ##########################
$selectParams1 = @{
Id = "Category1-$Type"
Label = "Category 1"
FullWidth = $true
}
if ($Type -eq "Edit") {
$selectParams1['DefaultValue'] = $($Session:Categories.Category_1)
}
New-UDSelect @selectParams1 -Option {
$Session:E5Cat1 | ForEach-Object {
New-UDSelectOption -Name $_.Name -Value $_.ID
}
} -OnChange {
$Session:Query_CategoryDefaults2 = "SELECT ID, Name FROM Category2 WHERE Category1_Id = $EventData ORDER BY SortOrder"
$Session:Query_CategoryDefaults3 = $null
Sync-UDElement -Id "Category2-$Type-Dynamic" -Wait
Sync-UDElement -Id "Category3-$Type-Dynamic" -Wait
Set-UDElement -Id "Category2-$Type" -Properties @{ Disabled = $false; Value = '' }
Set-UDElement -Id "Category3-$Type" -Properties @{ Disabled = $true; Value = '' }
}
## Category Selection 2 ##########################
$selectParams2 = @{
Id = "Category2-$Type"
Label = "Category 2"
FullWidth = $true
Disabled = $true
}
if ($Type -eq "Edit") {
$selectParams2['DefaultValue'] = $($Session:Categories.Category_2)
}
New-UDDynamic -Id "Category2-$Type-Dynamic" -Content {
New-UDSelect @selectParams2 -Option {
if ($Session:Query_CategoryDefaults2) {
$Session:E5Cat2 = Invoke-DbaQuery -SqlInstance $Cache:E5_ServerName -Database $Cache:E5_Database -Query $Session:Query_CategoryDefaults2
$Session:E5Cat2 | ForEach-Object {
New-UDSelectOption -Name $_.Name -Value $_.ID
}
}
else {
New-UDSelectOption -Name "NULL" -Value 0
}
} -OnChange {
$Session:Query_CategoryDefaults3 = "SELECT ID, Name FROM Category3 WHERE Category2_Id = $EventData ORDER BY SortOrder"
#Sync-UDElement -Id "Category3-$Type-Dynamic" -Wait
Sync-UDElement -Id "Category3-$Type-Dynamic"
Start-Sleep -s 1
Set-UDElement -Id "Category3-$Type" -Properties @{ Disabled = $false; Value = '' }
}
}
## Category Selection 3 ##########################
$selectParams3 = @{
Id = "Category3-$Type"
Label = "Category 3"
FullWidth = $true
Disabled = $true
}
if ($Type -eq "Edit") {
$selectParams3['DefaultValue'] = $($Session:Categories.Category_3)
}
New-UDDynamic -Id "Category3-$Type-Dynamic" -Content {
New-UDSelect @selectParams3 -Option {
if ($Session:Query_CategoryDefaults3) {
$Session:E5Cat3 = Invoke-DbaQuery -SqlInstance $Cache:E5_ServerName -Database $Cache:E5_Database -Query $Session:Query_CategoryDefaults3
$Session:E5Cat3 | Out-File "C:\Temp\Cat3.txt"
$Session:E5Cat3 | ForEach-Object {
New-UDSelectOption -Name $_.Name -Value $_.ID
}
}
else {
New-UDSelectOption -Name "NULL" -Value 0
}
}
}
}
The select 2 object works fine, when select 1 has a value change it enables and refreshes the data in there. Select 3 on the other hand, doesnt work with Sync-UDElement -Wait
it stays disabled. The only way i can fix this currently is to revert the select 2 OnChange event to what i was doing prior to the -Wait command being available. Basically just doing a normal Sync-UDElement with a sleep after. This works unless you click around too fast.
Theres no errors that i can see, it just doesnt seem to sync when theres two or more with the -Wait parameter.