New-udselect/multiselect empty with -selected

Encosed Sample code … Works fine but …
If you do not select/deselect a value but first click on button, the selected value is empty
would expect to get the values with “-selected” …

$global:mypage = New-UDPage -ID mypage -Name “mypage” -Endpoint {

  # Input usualy from Database ...
   $dbs=@()

   $myrow = @{
     name   = 'Row1'
     number = '1'
   }                       
   $dbs=$dbs+$myrow

   $myrow = @{
      name   = 'Row2'
      number = '2'
   }                       
   $dbs=$dbs+$myrow

   $myrow = @{
     name   = 'Row3'
     number = '3'
   }                       
   $dbs=$dbs+$myrow 

  # Card
  New-UDCard  -Content {

     # Select
     New-UDSelect -ID myselect -MultiSelect -Label ‘select me’ -Option {
        foreach ( $value in $dbs ) {
           New-UDSelectOption -Name $value.name -Value $value.number -Selected
        }
     }
     
     # Button
     New-UDButton -Icon ticket -Text "Button" -OnClick {                                                              
        $myvar=get-UDElement -id myselect
        $myvar=$myvar.Attributes['value']  
        Show-UDToast -Message "> $myvar <" -Duration 2000                                     
     }
  }

}

$Dashboard = New-UDDashboard -Title “Multiselect” -Page $global:mypage
Get-UDDashboard | Stop-UDDashboard
Start-UDDashboard -Dashboard $Dashboard -Port 10000 -AllowHttpForLogin

Workaround:
Use “OnChange” with New-UDSelect …

} -OnChange {
$session:mymemory=1
}

if $session:mymemory is not equal 1 no selection has been made … so take the Default …

Indeed, it seem like the -selected should make EACH item in your for loop be selected.

Even after trying some tricks like ensuring only the first item was selected I could not get the control to take the specified selections.

I DID back test this - this behavior worked as expected in 2.3.0, but DOES NOT in 2.4 and 2.5. I will go
ahead and file this bug on the github issue tracker!

Reported: https://github.com/ironmansoftware/universal-dashboard/issues/959

Nice Find!


I opened a PR with the fix. thanks.