Add items to a collection via a modal

This example shows how to add a button, the opens a modal with an input that you can then submit to add items to a grid.


Start-UDDashboard -Dashboard (New-UDDashboard -Title 'Dashboard' -Content {

    New-UDButton -Icon plus -Floating -OnClick {
        Show-UDModal -Content {
            New-UDInput -Title "Add Item" -Endpoint {
                param($Item)

                if ($null -eq $Session:Items)
                {
                    $Session:Items = New-Object System.Collections.ArrayList
                }

                $Session:Items.Add([PSCustomObject]@{
                    Name = $Item
                })

                Sync-UDElement -Id 'Grid'
                Hide-UDModal
            }
        }
    }

    New-UDGrid -Id 'Grid' -Title "Items" -Endpoint {
        $Session:Items | Out-UDGridData
    }

}) -Port 10000 -Force
6 Likes