I am working on a dashboard with a many select options, and would like to output the text of the chosen option once a button is clicked. But while I am able to get the Value, getting the -Name parameter, or the text of the option, seems not to be as straightforward. Here is a simple example:
New-UDDashboard -Title 'PowerShell Universal' -Content {
New-UDSelect -Id "dayCombo" -Option {
New-UDSelectOption -Name 'Sunday' -Value 1
New-UDSelectOption -Name 'Monday' -Value 2
New-UDSelectOption -Name 'Tuesday' -Value 3
New-UDSelectOption -Name 'Wednesday' -Value 4
New-UDSelectOption -Name 'Thursday' -Value 5
New-UDSelectOption -Name 'Friday' -Value 6
New-UDSelectOption -Name 'Saturday' -Value 7
} -DefaultValue 1
New-UDButton -Text 'OnBoard' -OnClick {
$comboChoice = (Get-UDElement -Id "dayCombo").value
$day = Switch ($comboChoice) {
2{
"Monday"
}
3 {
"Tuesday"
}
4 {
"Wednesday"
}
5 {
"Thursday"
}
Default {
"Sunday"
}
}
Show-UDToast -Message $day -Duration 3000
}
}
Now, I know there is a long-standing issue with getting anything unless the option has changed. So you have to do something akin to returning the -DefaultValue if blank. But the only way thus far I have found to return the actual text of the option chosen is the double-hop above: first get the Value and then use a Switch statement to assign the text.
I am just curious if there is an easier way to grab the Name parameter. I could set the Name and Value to be the same, but in my actual dashboard some of the option text is very long, so doing it that way would be ugly at best. I would think I could grab this Name parameter, and am curious if I am just not hitting on the correct syntax?
Product: PowerShell Universal
Version: 2.10.0