Basics
Contains all Basic methods.
The Text
field is a basic text input field in MoonShine. This field is equivalent to <input type="text">
use MoonShine\UI\Fields\Text; Text::make('Title')
<x-moonshine::field-container label="Title"> <x-moonshine::form.input type="text" name="title" /></x-moonshine::field-container>
Basic methods
Placeholder
The placeholder()
method allows you to set placeholder text for the field.
placeholder(string $value)
Text::make('Username', 'username') ->placeholder('Enter username')
Mask
The mask()
method allows you to apply a mask to the entered text.
mask(string $mask)
Example usage:
Text::make('Phone', 'phone') ->mask('+7 (999) 999-99-99')
Tags
The tags()
method transforms the text field into a tag input field.
tags(?int $limit = null)
Text::make('Tags', 'tags') ->tags(5)
Disable escaping
The unescape()
method disables HTML tag escaping in the field value.
unescape()
Example usage:
Text::make('HTML Content', 'content') ->unescape()
Extensions
Fields support various extensions to assist with input control.
Copy
The copy()
method adds a button to copy the field value.
copy(string $value = '{{value}}')
Example usage:
Text::make('Token', 'token') ->copy()
Hide value
The eye()
method adds a button to show/hide the field value (e.g., for passwords).
eye()
Example usage:
Text::make('Password', 'password') ->eye()
Lock
The locked()
method adds a lock icon to the field.
locked()
Example usage:
Text::make('Protected field', 'protected_field') ->locked()
Suffix
The suffix()
method adds a suffix to the input field.
suffix(string $ext)
Example usage:
Text::make('Domain', 'domain') ->suffix('.com')
Editing in preview mode
This field supports editing in preview mode.
If you want to avoid input errors, you can use the Lock extension.
Text::make('Name')->updateOnPreview()->locked(),
Reactivity
This field supports reactivity.