Multiselect Autocomplete shows Values instead of Name if more are selected
Hi,
not sure if this a bug or i do something wrong.
Im using the Autocomplete Component to select one or more users from a list.
For the Name i build something out of Username and the Title / Position and the Value is the ObjectGuid for the script to use afterwards.
If i now select one entry it works without a problem, but as soon as i add another different entry, the one before transforms into the Value instead of showing the Name.
The code for the Autocomplete Component ist the following:
The $ADUsers is a cached list of our AD Users.
New-UDAutocomplete -Id "txtMailboxAccess" -Label "User" -Multiple -FullWidth -Icon (New-UDIcon -Icon "user" -Solid) -OnLoadOptions {
$ADUsers | Where-Object {$_.userprincipalname -like "*$Body*" -or $_.samaccountname -like "*$Body*"} | ForEach-Object {
New-UDAutoCompleteOption -Name "$($_.displayName) ($($_.title) | $($_.department))" -Value $_.ObjectGuid
} | ConvertTo-Json
}
Does anybody know how to solve this?
Thank you!
d38d64b4-5cc7-43ae-9102-cc5d2a70cb2a.png
Hi,
not sure if this a bug or i do something wrong.
Im using the Autocomplete Component to select one or more users from a list.
For the Name i build something out of Username and the Title / Position and the Value is the ObjectGuid for the script to use afterwards.
If i now select one entry it works without a problem, but as soon as i add another different entry, the one before transforms into the Value instead of showing the Name.
The code for the Autocomplete Component ist the following:
The $ADUsers is a cached list of our AD Users.
New-UDAutocomplete -Id "txtMailboxAccess" -Label "User" -Multiple -FullWidth -Icon (New-UDIcon -Icon "user" -Solid) -OnLoadOptions {
$ADUsers | Where-Object {$_.userprincipalname -like "*$Body*" -or $_.samaccountname -like "*$Body*"} | ForEach-Object {
New-UDAutoCompleteOption -Name "$($_.displayName) ($($_.title) | $($_.department))" -Value $_.ObjectGuid
} | ConvertTo-Json
}
Does anybody know how to solve this?
Thank you!
@simon
Yes. To solve this, make sure already selected users are still included in the results returned by -OnLoadOptions. New-UDAutocomplete -Multiple stores the selected Value, then maps it back to Name from the current options list. If the previous user is no longer in that list, the control can only display the GUID.
Also cast the GUID to string:
New-UDAutoCompleteOption -Name "$($_.displayName) ($($_.title) | $($_.department))" -Value ([string]$_.ObjectGuid)