Set-UDElement reset by Sync-UDElement

Product: PowerShell Universal
Version: 4.1.4

Im not sure if this is a bug or if there is some parameter I’m missing to wait for the sync to complete first but what I am doing is syncing an element and then setting an element afterwards:

New-UDSelect -ID "sel1" -Option {
    $E5Cat1 | Foreach-Object {
        New-UDSelectOption -Name $_.Name -Value $_.ID
} -OnChange {
    $Session:query_Cat2 = "SELECT ID, Name FROM Category2 WHERE Category1_Id = $EventData ORDER BY SortOrder"
    $Session:Query_Cat3 = $null
    Sync-UDElement -Id 'sel2-Dynamic'
    Sync-UDElement -Id 'sel3-Dynamic'
    start-sleep -Milliseconds 300
    Set-UDElement -Id "sel2" -Properties @{ Disabled = $false}
    Set-UDElement -Id "sel3" -Properties @{ Disabled = $true}

So the behavior should be that Select 2 and 3 are disabled until select 1 has a value, and that value changes the SQL query that is used to dynamically fill the other selects. What I’ve noticed is that unless I put a sleep in there Select 2 flashes to enabled but then back off. Im assuming that means that Sync-UDElement runs in the background.

Sync-UDElement is non-blocking. We could add a -Wait parameter to it to make it block until the element is loaded.

Thanks Adam, that would be very helpful as what I’ve done is not very consistent. Sometimes it stays disabled sometimes not.

Can you clarify how we can add a -Wait parameter? I experience similar problems with components.

Theres an enhancement listed on the issue tracker: -Wait for Sync-UDElement · Issue #2732 · ironmansoftware/issues · GitHub for now I’m just using a sleep until this gets added in.