Telephone input
Create telephone inputs in your forms.
Last updated
Was this helpful?
Create telephone inputs in your forms.
Last updated
Was this helpful?
Use the telInput()
function to create telephone inputs in your forms. It uses the HTML <input type="tel">
element which provides built-in telephone format validation.
Generates the following Markdown-like syntax:
Add the required
parameter to make the field mandatory:
Generates the following Markdown-like syntax:
The following is the overview of the function:
name
string
A unique name for your form field that you'll use to identify the user's response.*
params
object
*Avoid values for the name
argument which may be the names of HTML attributes, such as "name"
, "role"
, "id"
, etc. This is because by default, the form's template string is first sanitized using DOMPurify, and these values may be removed to prevent DOM clobbering.
These parameters are common to all form fields:
question
(required)
string
The main question or label of the form field.
required
true
(boolean
)
When set, the field becomes required.
description
string
Any extra information that the user may need to fill out the form. Appears right below the question.
fieldSize
"sm"
When set to "sm"
, the font sizes of the question, description, and answer are made smaller.
labelStyle
"classic"
When set to "classic"
, the question and description of the form field are made smaller.
subfield
true
(boolean
)
When set, the question and description of the form field are made smaller. Functionally the same as setting labelStyle
to "classic"
.
disabled
true
(boolean
)
When set, the input is disabled.
autofocus
true
(boolean
)
When set, the input will be automatically focused when the parent slide becomes active, or immediately after page load.
id
string
The id
attribute of the form field container.
classNames
string[]
attrs
Array<{ name: string, value: string }>
Other HTML attributes of the form field. Each attribute has a name
and value
property.
displayCondition
{ dependencies: string[], condition: string }
placeholder
string
Sets the placeholder
attribute of the input.
maxlength
number
If set, this becomes the maximum number of allowed characters in the input.
pattern
string
If set, the input value must match the given pattern.
value
string
If set, this becomes the default value of the input.
country
string
The default country code (e.g., "US"
, "CA"
, "GB"
, etc. Defaults to "US"
if not specified. ISO alpha-2 format.
availableCountries
string[]
Array of available country codes (e.g., ["US", "CA", "GB"]
).
Generates the following Markdown-like syntax:
Generates the following Markdown-like syntax:
Add CSS classes and other HTML attributes using the classNames
and attrs
parameters. Please note, these class names and attributes are added to the <div>
or <fieldset>
container that contains the actual input field(s).
Generates the following Markdown-like syntax:
Please see the available CSS utility classes.
Conditionally show or hide a telephone input field using the displayCondition
parameter. It works as follows:
dependencies
lists the fields to watch.
condition
is the expression that must be true to show the field. This must be a valid Nunjucks expression.
For instance, in the example below, the mobile phone input will only show up if the user indicates they want to receive SMS notifications.
Generates the following Markdown-like syntax:
The selected country code is sent separately from the actual phone number during form submission. For example, if we had an input with the name contactNumber
, the actual number would be sent under the contactNumber
key, while the selected country code would be sent under the contactNumberCountryCode
.
An object containing all the configuration parameters for your telephone input field (see the below for the full list of options).
The CSS class names of the form field. .
Controls when the field is shown. The dependencies
lists the fields to watch, and condition
is the expression that must be true to show the field. The condition
must be a valid expression. .