Skip to main content

PhoneNumberInput

Collects a phone number: a country selector next to the national digits.

The stored value is always the full international number (+420123456789); the split into country code and national part exists only in the UI.

Example​

<PhoneNumberInput
source="phone"
defaultRegion="CZ"
allowedRegions={['CZ', 'SK']}
/>

Props​

NameTypeDefaultDescription
source (required)string—Name of the field in the form record
labelstring | ReactElement | falselabel from the schemafalse hides the label
helperTextstring | ReactElement | falsehelpText from the schemaText under the input
validateValidator | Validator[]from the schemaReact Admin validators
fullWidthbooleantrueStretches the input to its container
placeholderstring—Placeholder for the national part
defaultRegionstringfirst allowed regionCountry preselected for an empty value
allowedRegionsstring[]all known regionsRestricts the country selector

The schema layer maps options.phone.defaultRegion and options.phone.allowedRegions onto the two props above before rendering this component directly.

Digits are grouped as you type according to the selected country, and the caret keeps its place among the digits rather than jumping over the separators. Clearing the national part stores null.

Schema mapping​

type: "string" with format: "phone":

{"name": "phone", "type": "string", "format": "phone",
"options": {"phone": {"defaultRegion": "CZ", "allowedRegions": ["CZ", "SK"]}}}
from django.db import models
from habarico.models import PhoneNumberField


class Customer(models.Model):
name = models.CharField(max_length=255)
phone = PhoneNumberField(region="CZ", allowed_regions=["CZ", "SK"], blank=True)

See also​