Skip to content

Text input

The text input collects a single line of text. Create one with TextInput::make(), passing the field name and its label.

TextInput::make('name', 'Team name')
->placeholder('My team')
->required()

->placeholder() sets the muted hint shown while the field is empty. It is not a value — an empty field still submits as empty.

Call ->email() to set the HTML input type to email and apply email validation:

TextInput::make('email', 'Email address')
->email()
->placeholder('[email protected]')

->prefix() and ->suffix() attach a small adornment to the start or end of the input — a unit, a currency symbol, or an icon. Pass a string for literal text, or an Icon enum case for an icon:

TextInput::make('price', 'Price')
->prefix('$')
->suffix('USD')
TextInput::make('search', 'Search')
->prefix(Icon::Search)

The rule is the argument type: an Icon enum (or any backed enum) renders as an icon, a plain string renders as text. To use an icon that isn’t an Icon case — for example a host app’s own sprite name — reach for the explicit Affix value object:

use Lattice\Lattice\Support\Affix;
TextInput::make('search', 'Search')->prefix(Affix::icon('custom-glyph'));
TextInput::make('weight', 'Weight')->suffix(Affix::text('kg'));

->autoComplete() sets the HTML autocomplete attribute so the browser can offer saved values. Pass any valid token, such as organization, username, or off.

TextInput::make('company', 'Company')->autoComplete('organization');

->autoFocus() focuses the field when the form mounts. Use it on the first field only.

TextInput::make('name', 'Team name')->autoFocus();

->tabIndex() overrides the keyboard tab order. Most forms should rely on the natural document order instead.

TextInput::make('name', 'Team name')->tabIndex(1);

TextInput shares label, default value, required, disabled, read-only, and visibility options with every field — see Fields. For validation and conditional behavior, see Validation and Conditional fields.