# Textbox

A textbox lets users enter and edit text.

## Textbox

![](/files/FrFSwIIKIB7dVgwxQKSy)

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

## 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.

![](/files/y3XfcveeKBA2iCja9a3H)

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

### Number Type

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

![](/files/v5Dexa23Fld8ohtgWrEr)

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

## 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`.

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

## Interaction

### Retrieving a textbox value

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

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

### Setting the textbox value

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

New-UDButton -OnClick {

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

} -Text "Get textbox value"
```

## Icons

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

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

![](/files/ggjrg9ERjjtJnLGePAq6)

## Masking

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

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

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.

```powershell
New-UDTextbox -OnEnter {
    Invoke-UDEndpoint -Id 'submit' -Session
}

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

## OnBlur

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

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

## OnValidate

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

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

## API

[New-UDTextbox](https://github.com/ironmansoftware/universal-docs/blob/v5/cmdlets/New-UDTextbox.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/textbox.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.
