@adam
I am opening this thread because I cam across an issue and found couple of github issues and forum enties without a bugfix yet.
Forum
Github
I had a look into the code and the fix should be in the render function (in my opinion).
after var selectedOption = ...
if no selected option is found (only for multi select) set the current state to the selected values (add the same logic as in OnClick after).
For non MultiSelect elements set the first item to the current state value
https://github.com/ironmansoftware/universal-dashboard/blob/master/src/UniversalDashboard.Materialize/Components/ud-select.jsx
Example code:
New-UDCard -Title 'Select' -Content {
New-UDSelect -Id 'Select' -Label 'Select' -Option {
@("One", "Two", "Three") | % {
New-UDSelectOption -Name $_ -Value (New-Guid).Guid
}
}
New-UDButton -Text "Get Select" -OnClick (New-UDEndpoint -Endpoint {
$UDElement = Get-UDElement -id "Select"
$Value=$UDElement.Attributes['value']
Show-UDToast -Message "Value: $Value" -Duration 5000
})
}
New-UDCard -Title 'Multi Select' -Content {
New-UDSelect -Id 'MultiSelect' -Label 'Select' -MultiSelect -Option {
@("One", "Two", "Three") | % {
New-UDSelectOption -Name $_ -Value (New-Guid).Guid -Selected
}
}
New-UDButton -Text "Get MultiSelect" -OnClick (New-UDEndpoint -Endpoint {
$UDElement = Get-UDElement -id "MultiSelect"
$Value=$UDElement.Attributes['value']
Show-UDToast -Message "Value: $Value" -Duration 5000
})
}