op_Addition to session variable array

Hi,

I have a simple input field and a button. If the button is clicked the input is stored in a session variable and displayed in a table:

New-UDTextbox -Id "Givename" -Label "Givename" -FullWidth
New-UDTextbox -Id "Surname" -Label "Surname" -FullWidth

$session:namesList = @()
 New-UDButton -Text "Add" -OnClick {
    $session:namesList += @{ "Givename" = (Get-UDElement -Id "Givename").value; "Surname"=(Get-UDElement -Id "Surname").value}
    Sync-UDElement -Id "namesTable"
}
    
New-UDParagraph -Content {
    New-UDDynamic -Id "namesTable" -Content {
        New-UDTable -Data $session:namesList
    }
} 

Once the button is clicked the input will be displayed ONCE but any further input won’t be added.
However if I already add data into the array during creation it is working as intended:

$session:namesList = @(@{ "Givename" = "John"; "Surname"="Doe"},@{ "Givename" = "Jane"; "Surname"="Doe"})
Product: PowerShell Universal
Version: 1.5.8

I’ve found a solution by using PSObjects instead of hashtables and declaring the variable as array for each op_addition:

$session:namesList = @()
[array]$session:namesList += New-Object PSObject -Property @{ Givename = (Get-UDElement -Id "Givename").value; Surname = (Get-UDElement -Id "Surname").value}
2 Likes