# Autocomplete

The autocomplete is a normal text input enhanced by a panel of suggested options.

## Static List of Options

Creates a basic autocomplete with a static list of options

```powershell
New-UDAutocomplete -Options @('Test', 'Test2', 'Test3', 'Test4')
```

## Dynamic List of Options

When text is typed, it can be filtered with `OnLoadOptions`. `$Body` will contain the current text that is typed.

This example filters the array with `Where-Object`.

```powershell
New-UDAutocomplete -OnLoadOptions { 
    @('Test', 'Test2', 'Test3', 'Test4') | Where-Object { $_ -like "*$Body*" } | ConvertTo-Json
}
```

## OnChange

`$Body` contains the currently selected item. The OnChange event will fire when the user selects one or more items.

```powershell
New-UDAutocomplete -OnLoadOptions { 
    @('Test', 'Test2', 'Test3', 'Test4') | Where-Object { $_ -like "*$Body*" } | ConvertTo-Json
} -OnChange {
    Show-UDToast $Body 
}
```

## Icon

![](/files/IvSKREVeP3qL6Rxf1LRG)

You can place an icon before an autocomplete by using the `-Icon` parameter.

```powershell
New-UDAutocomplete -Options @("Test", "No", "Yes") -Icon (New-UDIcon -Icon 'Users') 
```

## OnEnter

OnEnter is triggered when the user presses the enter key within the autocomplete.

```powershell
New-UDAutocomplete -Options @("Test", "No", "Yes") -onEnter {
    Show-UDToast ((Get-UDElement -Id 'ac').value)
} -Id 'ac'
```

## Options

You can use `New-UDAutoCompleteOption` to specify name and values.

```powershell
New-UDAutocomplete -Options @(
    New-UDAutoCompleteOption -Name 'Adam D' -Value '1'
    New-UDAutoCompleteOption -Name 'Sarah F' -Value '2'
    New-UDAutoCompleteOption -Name 'Tom S' -Value '3'
)
```

## API

* [New-UDAutocomplete](https://github.com/ironmansoftware/universal-docs/blob/v5/cmdlets/New-UDAutocomplete.txt)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.powershelluniversal.com/apps/components/inputs/automcomplete.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
