TextInput
A single line input for text, e-mail addresses, URLs, phone numbers and plain numbers.
use Anvil\Schema\Fields\TextInput;
TextInput::make('name')->required()->maxLength(120),TextInput::make('email')->email()->required()->rules('is_unique[contacts.email]'),TextInput::make('website')->url(),TextInput::make('phone')->tel()->maxLength(40)->autocomplete('tel'),TextInput::make('domain')->prefix('https://')->suffix('/'),Options
Section titled “Options”| Option | Effect | Default |
|---|---|---|
email() |
type="email", rule valid_email |
text |
url() |
type="url", rule valid_url_strict[https,http] (only http and https) |
text |
tel() |
type="tel" (mobile keyboards show digits); no format rule, add one with rules() |
text |
numeric() |
type="number" with step="any", rule numeric; removes the length limit |
text |
integer() |
like numeric(), rule integer |
text |
maxLength(n) |
rule max_length[n] and maxlength attribute; null for no limit |
255 |
minLength(n) |
rule min_length[n] |
none |
prefix('…'), suffix('…') |
text before / after the input (input group); also shown read-only | none |
autocomplete('…') |
autocomplete attribute, e.g. email, tel, off |
none |
Plus the options of every field.
numeric() and integer() use the browser’s number input and the
CodeIgniter rules, which expect a point as decimal separator. For amounts,
decimals in the user’s locale and limits use a
NumberInput instead.
Saved value
Section titled “Saved value”The input is trimmed. An empty optional field is saved as null; a
required field cannot be empty.
Validation
Section titled “Validation”string (or valid_email, valid_url_strict[https,http], numeric,
integer by type), then max_length[n] and min_length[n] when set, then
the rules of rules():
TextInput::make('personnel_number')->required()->maxLength(30)->rules('alpha_dash'),// required|string|max_length[30]|alpha_dashRead-only
Section titled “Read-only”The value with prefix and suffix as plain text.
A string; the JSON Schema is derived from the rules
(format: email, maxLength, …). JSON numbers are accepted for numeric
inputs and converted to strings before validation.