Skip to main content

Phone Input

Rocket 2.0

The Phone Input component is a field for entering a phone number with its country, such as a customer's contact number. It formats the number as the user types and checks that it is valid for the chosen country.

Properties​

Property
Description
Expected Value
LabelText shown above the field.Text. Default: Phone number
Help textHint text shown under the field.Text
PlaceholderText shown in the field when it is empty.Text. Default: Enter phone number
Default value (E.164 or a national number)Number filled in when the app loads, such as +14155550123 or a local number in Default country. A number with a + country code picks its own country.Text
Default country (ISO code)Two-letter country code selected when the app loads, such as US or GB.Text. Default: US
Countries offered (ISO codes; empty: all)Country codes to offer in the country list, such as ['US', 'CA', 'GB']. Leave empty to offer every country.Array
Enable country changeLets the user pick another country from a searchable list. When off, the country stays fixed.On or off. Default: On
Show country flagShows the country's flag next to its calling code.On or off. Default: On
Show clear buttonShows a button in the field that clears the number.On or off. Default: Off

Additional Actions​

Each of these can be switched on or off, or set with a logical expression by clicking fx.

Property
Description
Expected Value
VisibilityShows or hides the component. Hidden components keep their space unless Collapse when hidden is on.On or off. Default: On
Collapse when hiddenRemoves the hidden component's space, so the components below it move up.On or off. Default: Off
Loading stateShows the component's loading look and blocks interaction, for example while a query runs.On or off. Default: Off
DisableStops the user from interacting with the component.On or off. Default: Off
Dynamic heightLets the component grow with its content in the running app instead of keeping a fixed height.On or off. Default: Off

Devices​

Property
Description
Expected Value
Show on desktopShows the component in the desktop layout.On or off. Default: On
Show on mobileShows the component in the mobile layout.On or off. Default: Off

Events​

Add a handler from the Events section of the properties panel. See Event Triggers for the steps.

Event
Description
On changeTriggers when the number or the country changes.
On enter pressedTriggers when the user presses Enter in the field.
On focusTriggers when the field gets focus.
On blurTriggers when the field loses focus.

Component Specific Actions (CSA)​

Run these from an event handler with Control Component, or from a RunJS query. See Component Specific Actions.

Action
Description
How To Access
Set valueSets the number to the given Value, in Country when one is given.components.phoneinput1.setValue("", "")
Set country codeSwitches to the given Country code, either a two-letter code such as GB or a calling code such as +44, keeping the digits typed.components.phoneinput1.setCountryCode("")
ClearEmpties the number.components.phoneinput1.clear()
Set focusMoves keyboard focus to the field.components.phoneinput1.setFocus()
Set blurRemoves focus from the field.components.phoneinput1.setBlur()
Set visibilityShows the component when true, hides it when false.components.phoneinput1.setVisibility(false)
Set disableDisables the component when true, enables it when false.components.phoneinput1.setDisable(false)
Set loadingTurns the loading state on with true, off with false.components.phoneinput1.setLoading(false)

Exposed Variables​

Variable
Description
How To Access
labelText shown above the field.{{components.phoneinput1.label}}
descriptionHint text shown under the field.{{components.phoneinput1.description}}
placeholderText shown in the field when it is empty.{{components.phoneinput1.placeholder}}
defaultValueNumber filled in when the app loads, such as +14155550123 or a local number in Default country. A number with a + country code picks its own country.{{components.phoneinput1.defaultValue}}
defaultCountryTwo-letter country code selected when the app loads, such as US or GB.{{components.phoneinput1.defaultCountry}}
onlyCountriesCountry codes to offer in the country list, such as ['US', 'CA', 'GB']. Leave empty to offer every country.{{components.phoneinput1.onlyCountries}}
isCountryChangeEnabledLets the user pick another country from a searchable list. When off, the country stays fixed.{{components.phoneinput1.isCountryChangeEnabled}}
showFlagShows the country's flag next to its calling code.{{components.phoneinput1.showFlag}}
showClearBtnShows a button in the field that clears the number.{{components.phoneinput1.showClearBtn}}
valueThe full number in international format, such as +14155550123.{{components.phoneinput1.value}}
countryThe two-letter code of the selected country, such as US.{{components.phoneinput1.country}}
countryCodeThe calling code of the selected country, such as +1.{{components.phoneinput1.countryCode}}
formattedValueThe number formatted for display.{{components.phoneinput1.formattedValue}}
isValidNumberWhether the number is valid for the selected country.{{components.phoneinput1.isValidNumber}}
isVisibleWhether the component is visible.{{components.phoneinput1.isVisible}}
isLoadingWhether the component is in its loading state.{{components.phoneinput1.isLoading}}
isDisabledWhether the component is disabled.{{components.phoneinput1.isDisabled}}

Styles​

Style
Default
Label colorTheme: Primary text
Help text colorTheme: Placeholder text
Field backgroundTheme: Surface 1
Field text colorTheme: Primary text
Placeholder colorTheme: Placeholder text
Field border colorTheme: Default border
Accent (focus ring, selection)Theme: Brand primary
Error color (message and border)Theme: Error
Field radius—
Country button backgroundtransparent
Country button text colorTheme: Primary text
Popover backgroundTheme: Surface 1
Popover text colorTheme: Primary text
Popover item hover backgroundTheme: Surface 3
Selected item text color (on the accent)Theme: Surface 1
Box shadow0px 0px 0px 0px #00000040

A default that starts with Theme: follows the app's theme until the style is set to another value. See App Themes.