Remove-UDElement Error

avatar
Product: PowerShell Universal
Version: 3.9.13


I am attempting to toggle between a few tables. The initial table is always rendered by the New-UDAutoComplete but each table change after that is via its respective button. I get an error using Remove-UDElement. Any ideas on how to resolve? Thanks!



a926a8902a9f46524902270ee3b7e227521cd4d8


e68c16845dd5681ca8baf423449f0b13017a0e13


7e3b2505cd13051d85d1d002955bb89f15189d8c


8dc798b7172aea4ca14c7e3cd34c2bb49a92c052

e68c16845dd5681ca8baf423449f0b13017a0e13.png

8dc798b7172aea4ca14c7e3cd34c2bb49a92c052.png

7e3b2505cd13051d85d1d002955bb89f15189d8c.png

a926a8902a9f46524902270ee3b7e227521cd4d8.png

avatar

Recommended Answer

I can reproduce this. I worked around it by using Sync-UDElement rather than Remove-UDElement on the UserTable. Since you are updating session variables, it will reevaluate and then hide the user table.

    $Session:Table = "User"
    New-UDButton -OnClick {
        $Session:Table = "Group"
        # Remove-UDElement -Id 'UserTable'
        Sync-UDElement -Id 'UserTable'
        Sync-UDElement -Id 'GroupTable'
    } -Text 'Sync'

    New-UDDynamic -Id 'GroupTable' -Content {
        if ($Session:Table -eq 'Group') {
            New-UDTable -Data (Get-Process | Select Name)
        }
    }

    New-UDDynamic -Id 'UserTable' -Content {
        if ($Session:Table -eq 'User')
        {
            New-UDTable -Data (Get-Process | Select ID)
        }
    }


Adam Driscoll
PowerShell Expert and Developer at Devolutions

All Comments (4)

avatar

I can reproduce this. I worked around it by using Sync-UDElement rather than Remove-UDElement on the UserTable. Since you are updating session variables, it will reevaluate and then hide the user table.

    $Session:Table = "User"
    New-UDButton -OnClick {
        $Session:Table = "Group"
        # Remove-UDElement -Id 'UserTable'
        Sync-UDElement -Id 'UserTable'
        Sync-UDElement -Id 'GroupTable'
    } -Text 'Sync'

    New-UDDynamic -Id 'GroupTable' -Content {
        if ($Session:Table -eq 'Group') {
            New-UDTable -Data (Get-Process | Select Name)
        }
    }

    New-UDDynamic -Id 'UserTable' -Content {
        if ($Session:Table -eq 'User')
        {
            New-UDTable -Data (Get-Process | Select ID)
        }
    }


Adam Driscoll
PowerShell Expert and Developer at Devolutions

avatar

thank you @Adam Driscoll
Is this using the -onChange New-UDAutoComplete or just using buttons?

avatar

I am going to test a bunch now

avatar

Worked perfectly, even with the New-UDAutoComplete onchange. What a phenomenal product this is!