I’m trying to make a confirm modal module for my PSU dashboard, but pretty sure it’s a powershell problem I’m having and not a Dashboard problem.
My module function looks like this so far:
function New-UDConfirm {
<#
.SYNOPSIS
Shows a confirm object in a modal, returns either true or false.
.DESCRIPTION
Shows a confirm object in a modal, returns either true or false.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $false,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true)]
[string]$Text = 'Are you sure?'
)
Show-UDModal -Content {
New-UDTypography -Text $Text
} -Footer {
New-UDButton -Text "Yes" -OnClick {
Hide-UDModal
return $true
} -Style @{"border-radius" = "4px"}
New-UDButton -Text "No" -OnClick {
Hide-UDModal
return $false
} -Style @{"border-radius" = "4px"}
} -Persistent
}
But even before any of the buttons is clicked, the function returns a null value.
I only started learning PS about a year ago, so I guess this is just some easy fix i didn’t catch about modules yet.
That almost worked but not quite.
First time I call New-UDConfirm it still get a null value back, then I click one of the buttons, and then next time I call the function, I get either true or false depending on what I clicked the first time. I can do this multiple times, clicking different things, but I always get the result from the last click.
I short, the result is one behind, with a null first time.
But I feel we are getting closer
This actually works, but you are right, it’s not as pretty as the modal.
Not to be a princess, but I would prefer a pretty solution with buttons instead of a dropdown menu