Microsoft.Common.TextBox UI element
The TextBox
user-interface (UI) element can be used to add unformatted text. The element is a single-line input field, but supports multi-line input with the multiLine
property.
UI sample
The TextBox
element uses a single-line or multi-line text box.
Example of single-line text box.
Example of multi-line text box.
Schema
{
"name": "nameInstance",
"type": "Microsoft.Common.TextBox",
"label": "Name",
"defaultValue": "contoso123",
"toolTip": "Use only allowed characters",
"placeholder": "",
"multiLine": false,
"constraints": {
"required": true,
"validations": [
{
"regex": "^[a-z0-9A-Z]{1,30}$",
"message": "Only alphanumeric characters are allowed, and the value must be 1-30 characters long."
},
{
"isValid": "[startsWith(steps('resourceConfig').nameInstance, 'contoso')]",
"message": "Must start with 'contoso'."
}
]
},
"visible": true
}
Sample output
"contoso123"
Remarks
- Use the
toolTip
property to display text about the element when the mouse cursor is hovered over the information symbol. - The
placeholder
property is help text that disappears when the user begins editing. If theplaceholder
anddefaultValue
are both defined, thedefaultValue
takes precedence and is shown. - The
multiLine
property is boolean,true
orfalse
. To use a multi-line text box, set the property totrue
. If a multi-line text-box isn't needed, set the property tofalse
or exclude the property. For new lines, JSON output shows\n
for the line feed. The multi-line text box accepts\r
for a carriage return (CR) and\n
for a line feed (LF). For example, a default value can include\r\n
to specify carriage return and line feed (CRLF). - If
constraints.required
is set totrue
, then the text box must have a value to validate successfully. The default value isfalse
. - The
validations
property is an array where you add conditions for checking the value provided in the text box. - The
regex
property is a JavaScript regular expression pattern. If specified, the text box's value must match the pattern to validate successfully. The default value isnull
. For more information about regex syntax, see Regular expression quick reference. - The
isValid
property contains an expression that evaluates totrue
orfalse
. Within the expression, you define the condition that determines whether the text box is valid. - The
message
property is a string to display when the text box's value fails validation. - It's possible to specify a value for
regex
whenrequired
is set tofalse
. In this scenario, a value isn't required for the text box to validate successfully. If one is specified, it must match the regular expression pattern.
Examples
The examples show how to use a single-line text box and a multi-line text box.
Single-line
The following example uses a text box with the Microsoft.Solutions.ArmApiControl control to check the availability of a resource name.
In this example, when you enter a storage account name and exit the text box, the control checks if the name is valid and if it's available. If the name is invalid or already exists, an error message is displayed. A storage account name that's valid and available is shown in the output.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "nameApi",
"type": "Microsoft.Solutions.ArmApiControl",
"request": {
"method": "POST",
"path": "[concat(subscription().id, '/providers/Microsoft.Storage/checkNameAvailability?api-version=2021-09-01')]",
"body": {
"name": "[basics('txtStorageName')]",
"type": "Microsoft.Storage/storageAccounts"
}
}
},
{
"name": "txtStorageName",
"type": "Microsoft.Common.TextBox",
"label": "Storage account name",
"constraints": {
"validations": [
{
"isValid": "[basics('nameApi').nameAvailable]",
"message": "[basics('nameApi').message]"
}
]
}
}
],
"steps": [],
"outputs": {
"textBox": "[basics('txtStorageName')]"
}
}
}
Multi-line
This example uses the multiLine
property to create a multi-line text box with placeholder text.
{
"$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
"handler": "Microsoft.Azure.CreateUIDef",
"version": "0.1.2-preview",
"parameters": {
"basics": [
{
"name": "demoTextBox",
"type": "Microsoft.Common.TextBox",
"label": "Multi-line text box",
"defaultValue": "",
"toolTip": "Use 1-60 alphanumeric characters, hyphens, spaces, periods, and colons.",
"placeholder": "This is a multi-line text box:\nLine 1.\nLine 2.\nLine 3.",
"multiLine": true,
"constraints": {
"required": true,
"validations": [
{
"regex": "^[a-z0-9A-Z -.:\n]{1,60}$",
"message": "Only 1-60 alphanumeric characters, hyphens, spaces, periods, and colons are allowed."
}
]
},
"visible": true
}
],
"steps": [],
"outputs": {
"textBox": "[basics('demoTextBox')]"
}
}
}
Next steps
- For an introduction to creating UI definitions, see CreateUiDefinition.json for Azure managed application's create experience.
- For a description of common properties in UI elements, see CreateUiDefinition elements.
- To learn more about functions, see CreateUiDefinition functions.