Use AutoComplete as a Select component

Here is the code :

New-UDPage -Name test -Title test -Url "/test/test" {   
  
    New-UDStepper -Children {
        New-UDStep -OnLoad {
            New-UDGrid -Container -Children {
                New-UDGrid -Item -LargeSize 2 -Children {
                    #New-UDTypography -Text 'Select multiple values and go to the next page'
                    #New-UDAutocomplete -Id 'AutoComplete' -Label 'AutoComplete' -Value $EventData.context.AutoComplete -Multiple -Options @('option1','option2','option3')
                    #Finally, you just have to put multiple values ​​in the value parameter to trigger the bug
                    New-UDAutocomplete -Id 'AutoComplete' -Label 'AutoComplete' -Value @('option1','option2') -Multiple -Options @('option1','option2','option3')
                }
            }
        }
        New-UDStep -OnLoad {
            #New-UDTypography -Text "Go back to the previous page to see the bug"
        }
    } -OnFinish {
        New-UDElement -Tag 'div' -Id 'result' -Content {$Body}
    }
}

I changed my code because, in the end, you just have to put multiple values ​​in the value parameter to trigger the bug.

Yes, the issue I had was when I clicked back, no data returned.

From what I found, the context data is only accepting [string] whereas the data context is in [string[]] for multiple value autocomplete. So, as a workaround, in PSUfolder\UniversalDashboard\Frameworks\v3\UniversalDashboard.MaterialUI.psm1, I removed the datatype under New-UDAutocomplete - left only $value to cater both single and array string values.

param(
        [Parameter()]
        [String]$Id = ([Guid]::NewGuid()),
        [Parameter()]
        [string]$Label,
        [Parameter()]
        $Value,
        [Parameter()]
        [Endpoint]$OnChange, 
        [Parameter(Mandatory, ParameterSetName = "Dynamic")]
        [Endpoint]$OnLoadOptions,

But in your case, I think you’re trying to set the default value for autocomplete. You can try to change the datatype.

1 Like

Apologies. I didn’t open the issue so this wasn’t taken care of. I’ve opened two issues to track both of these problems and get them fixed for the next version.

1 Like

thank you for the trick.

No problem.
Thank you for the always attentive and responsive support :wink:

I think both issues are from the same bug.

Has anyone (with Graph API for example) been able to dynamically populate user’s DisplayNames as the user types them?

For example the user types the letter S and the first 20 users with the letter S appear. Then they type A and 20 users with names that begin with SA appear…and so on.

Similar to PowerShell’s completers but those require a tab.

@kevinblumenfeld

$AllAADUser = #code to get all user display names

New-UDAutocomplete -Id 'User' -Label 'User' -Options $AllAADUser

Thank you for reply. Unfortunately, in this case there are 300k total users and it takes over ten minutes to pull the data. Outside of PUD, Completers use startswith and top=20 for example.

You will want to dynamically load the options. Here’s a pseudo-code example using the AD module.

New-UDAutocomplete -OnLoadOptions { 
    Get-ADUser -Filter "Name -Like '*$Body'" -ResultSetSize 20  -Properties Name | Select-Object -Expand Name | ConvertTo-Json
}