I am working on a form for a customer, and have noticed some difficulties pulling the value of the element. If I create a Select, something like this:
New-UDSelect -Label "CPU" -Id "CPU" -Option {
foreach ($item in 2..24) {
if ($item % 2 -eq 0) {
New-UDSelectOption -Name "$($item)" -Value "$($item)"
}
}
}
and then try to return the value of the element:
Show-UDToast -Message (Get-UDElement -Id "CPU").value
this only works if the user changes the Select from the default value of 2; otherwise the value is null. I can always change it to add something like “Select option” and make it default, like so:
New-UDSelect -Label "CPU" -Id "CPU" -DefaultValue "Select" -Option {
New-UDSelectOption -Name "Select" -Value "Select"
foreach ($item in 2..24) {
if ($item % 2 -eq 0) {
New-UDSelectOption -Name "$($item)" -Value "$($item)"
}
}
}
And that works (again, if the user changes from “Select” to another value). I am just curious why the value does not populate before changing, and if there is any other way besides adding a static entry to each element.
Product: PowerShell Universal
Version: 1.5.8