# Autocomplete

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

## Autocomplete with a static list of options

Creates a basic autocomplete with a static list of options

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

## Autocomplete with a dynamic list of options

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

This example filters the array with `Where-Object`.&#x20;

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

## Autocomplete with an OnChange script block

`$Body` contains the currently selected item.&#x20;

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

## API

* [New-UDAutocomplete](https://github.com/ironmansoftware/universal-docs/blob/master/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/master-1/userinterfaces/dashboards/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.
