Question around getting value from form elements

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

Hi, seen this question has gone unanswered for a few days now. So here is my pitch in to help out. I think you should have a butchers at this link

shows you how to set the default value and obtain value, so hopefully this should solve your problem :crossed_fingers:

Thanks for the suggestion. I checked out Adam’s example in that thread, and it is pretty much what I am doing now; he just manually specifies a default value. Since I am pulling all of my values for that select field from a sqlite db, and the values could change over time, I’d like to stay away from defining anything that is actually in the list statically as the default value - will probably stick with something like “Select item”. I wonder if this is worth reporting as a bug, since the value is there; it is just not being read? Thanks as always for the help.