After thinking about this more I think I know (to a degree) the underlying issue with a possible solution, issue being that the default -Value is just text input which get processed as if you simply provided an array of strings. Basically I think this can be solvable if the starting -Value were able to accept a AutocompletOption object as an input as well.
$PreviousComputerData #Data to prefill fields from somewhere else, ex. @{Name = ComputerName1; ObjectGUID = GUID1}
$ADComputers = Get-ADComputer -Filter * -Properties @(“ObjectGUID”, “Name”) #Example
$ComputerList = [System.Collections.Generic.List[Object]]::new()
foreach ($Comp in $ADComputers) {
$ComputerList.Add((New-UDAutocompleteOption -Name “$($Comp.Name)” -Value “$($Comp.ObjectGUID)”))
}
New-UDAutocomplete -Id ‘lstADComps’ -Label “Select a Computer” -Value “$($PreviousComputerData.Name)” -Options $ComputerList.ToArray()
New-UDButton -Text “Do Thing” -OnClick {
Show-UDToast -Message “$((ConvertTo-Json -InputObject (Get-UDElement -Id ‘lstADComps’)))” -Duration 15000
}
#Output with defaults value
{
“onChange”: null,
“id”: “lstADComps”,
“variant”: “standard”,
“assetId”: null,
“onEnter”: null,
“type”: “mu-autocomplete”,
“label”: “Select a Computer”,
“className”: “”,
“value”: “ComputerName1”, #<- This here should always be the value in the value section of the object and not the displayed value (or text, however you define it)
“isPlugin”: true,
“options”: [
{
“name”: “ComputerName1”,
“value”: “GUID1”,
“type”: “mu-autocomplete-option”
},
{
“name”: “ComputerName2”,
“value”: “GUID2”,
“type”: “mu-autocomplete-option”
}
],
“onLoadOptions”: null,
“icon”: null,
“fullWidth”: false,
“multiple”: false
}
#Output after changing the selection (even if you select the same thing)
{
“onChange”: null,
“id”: “lstADComps”,
“variant”: “standard”,
“assetId”: null,
“onEnter”: null,
“type”: “mu-autocomplete”,
“label”: “Select a Computer”,
“className”: “”,
“value”: “GUID1”, #<- This here should always be the value in the value section of the object and not the displayed value (or text, however you define it)
“isPlugin”: true,
“options”: [
{
“name”: “ComputerName1”,
“value”: “GUID1”,
“type”: “mu-autocomplete-option”
},
{
“name”: “ComputerName2”,
“value”: “GUID2”,
“type”: “mu-autocomplete-option”
}
],
“onLoadOptions”: null,
“icon”: null,
“fullWidth”: false,
“multiple”: false
}
I hope this makes more sense than my earlier, sleep deprived, ramblings