Unresponsive OnClick Param on New-UDButton

Let me preface this by saying, I’m certain I’m making a stupid mistake here, so I’m hoping someone can point me in the right direction.

I’m attempting to use the -OnClick parameter on New-UDButton however, it doesn’t appear to execute any code once clicked. My relevant code is below:

If necessary, I can post the entirety of my code, but this Row is the direct child of a dynamic UDPage.

New-UDRow -Id 'row-btns' -Endpoint {
    New-UDColumn -MediumSize 6 -LargeSize 6 -Content {
        New-UDButton -Text 'Edit' -Id 'domain-edit-btn' -Icon pencil -OnClick {
            New-UDInputAction -Toast "Clicked!" -Duration 2000
        }
    }

    New-UDColumn -MediumSize 6 -LargeSize 6 -Content {
        New-UDButton -Text 'Edit' -Id 'udf-edit-btn' -Icon pencil -OnClick {
            New-UDInputAction -Toast "Clicked!" -Duration 2000
        }
    }
}

Story of my entire coding/scripting life!

I’m not sure UDInputAction fits there. What happens if you just use:

Show-UDToast -Message “Yeet” -Duration 6000 -Title “Oof!” -Position topRight -BackgroundColor “#FF7F7F

Hi @jmknight2 there is no need to use the new-udinputaction for this, here is a working example I just chucked together for your post tested this and it all works1 :-
$Layout = ‘{“lg”:[{“w”:3,“h”:4,“x”:0,“y”:0,“i”:“grid-element-card1”,“moved”:false,“static”:false},{“w”:3,“h”:4,“x”:3,“y”:0,“i”:“grid-element-card2”,“moved”:false,“static”:false},{“w”:2,“h”:2,“x”:0,“y”:4,“i”:“grid-element-button”,“moved”:false,“static”:false},{“w”:2,“h”:1,“x”:3,“y”:4,“i”:“grid-element-button2”,“moved”:false,“static”:false}]}’
$test = New-UDPage -Name ‘Test’ -Content {
New-UDGridLayout -Layout $Layout -Content {
New-UDCard -Id “card1” -Title “Button 1” -TextSize Large
New-UDCard -Id “card2” -Title “Button 2” -TextSize Large
New-UDButton -Id “button” -Text “Press Me” -Icon pencil -OnClick { Show-UDToast -Message “you clicked the 1st button!” }
New-UDButton -Id “button2” -Text “No Press Me” -Icon pencil -OnClick { Show-UDToast -Message “you clicked the 2nd button!” }
}
}
$Dashboard = New-UDDashboard -Title “Button Test” -Pages @(
$test
)
Start-UDDashboard -Dashboard $Dashboard -Port 8091

Yup, see? I knew I was an idiot. You were both (@PorreKaj and @psDevUK) correct. Thank you for the help!

1 Like