> For the complete documentation index, see [llms.txt](https://docs.devolutions.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.devolutions.net/powershell-universal/apps/components/inputs/textbox.md).

# Textbox

Add text input fields to PowerShell Universal apps with password, number, and multiline types, masking, icons, and validation event handlers.

A textbox lets users enter and edit text.

## Textbox

{% code collapsedlinecount="10" %}

```powershell
New-UDTextbox -Label 'Standard' -Placeholder 'Textbox'
New-UDTextbox -Label 'Disabled' -Placeholder 'Textbox' -Disabled
New-UDTextbox -Label 'Textbox' -Value 'With value'
```

{% endcode %}

## Textbox Types

Textboxes can be switched to accept specific types, such as passwords, numbers, or emails.

### Password Type

A password textbox will mask the input.

{% code collapsedlinecount="10" %}

```powershell
New-UDTextbox -Label 'Password' -Type password
```

{% endcode %}

### Number Type

Only accepts numbers. Some browsers will include up and down arrows to increase and decrease the current value.

{% code collapsedlinecount="10" %}

```powershell
New-UDTextbox -Label 'Number' -Type number -Minimum 10 -Maximum 10000 -Value 1234
```

{% endcode %}

## Multiline

You can create a multiline textbox by using the `-Multiline` parameter. Pressing enter will add a new line. You can define the number of rows and the max number of rows using `-Rows` and `-RowsMax`.

{% code collapsedlinecount="10" %}

```powershell
New-UDTextbox -Multiline -Rows 4 -RowsMax 10
```

{% endcode %}

## Interaction

### Retrieving a textbox value

You can use `Get-UDElement` to get the value of a textbox

{% code collapsedlinecount="10" %}

```powershell
New-UDTextbox -Id 'txtExample' 
New-UDButton -OnClick {
    $Value = (Get-UDElement -Id 'txtExample').value 
    Show-UDToast -Message $Value
} -Text "Get textbox value"
```

{% endcode %}

### Setting the textbox value

{% code collapsedlinecount="10" %}

```powershell
New-UDTextbox -Id 'txtExample' -Label 'Label' -Value 'Value'

New-UDButton -OnClick {

    Set-UDElement -Id 'txtExample' -Properties @{
        Value = "test123"
    }

} -Text "Get textbox value"
```

{% endcode %}

## Icons

You can set the icon of a textbox by using the `-Icon` parameter and the `New-UDIcon` cmdlet.

{% code collapsedlinecount="10" %}

```powershell
New-UDTextbox -Id "ServerGroups" -Icon (New-UDIcon -Icon 'server') -Value "This is my server"
```

{% endcode %}

## Masking

You can use the `-MaskPattern` to define a mask for the textbox. The following is an example of a textbox mask.

{% code collapsedlinecount="10" %}

```powershell
New-UDTextbox -Id 'textbox16' -MaskPattern '+7 (000) 000-00-00'
```

{% endcode %}

The definition can contain

* `0` - any digit
* `a` - any letter
* `*` - any char
* other chars which are not in custom definitions supposed to be *fixed*
* `[]` - make input optional
* `{}` - include fixed part in unmasked value
* `` ` `` - prevent symbols shift back

If definition character should be treated as fixed it should be escaped by `\\` (E.g. `\\0`).

The masking for the textbox is controlled by [imaskjs](https://imask.js.org/guide.html#masked-pattern).

## OnEnter

The `-OnEnter` event handler is executed when the user presses enter in the text field. It is useful for performing other actions, like clicking a button, on enter.

{% code collapsedlinecount="10" %}

```powershell
New-UDTextbox -OnEnter {
    Invoke-UDEvent -Id 'submit' -Event onClick
}

New-UDButton -Id 'submit' -OnClick {
    Show-UDToast -Message 'From Textbox'
}
```

{% endcode %}

## OnBlur

The `-OnBlur` event handler is executed when the textbox loses focus.

{% code collapsedlinecount="10" %}

```powershell
New-UDTextbox -OnBlur {
    Show-UDToast "Blurred"
}
```

{% endcode %}

## OnValidate

Use the `-OnValidate` event handler to validate input typed in the textbox.

{% code collapsedlinecount="10" %}

```powershell
New-UDTextbox -OnValidate {
    if ($EventData.Length -lt 10)
    {
        New-UDValidationResult -ValidationError 'String needs to be longer than 10'
    }
}
```

{% endcode %}

## API

[New-UDTextbox](/powershell-universal/powershell-commands/new-udtextbox.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.devolutions.net/powershell-universal/apps/components/inputs/textbox.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
