Fields

Text

Basics

Contains all Basic methods.

The Text field is a basic text input field in MoonShine. This field is equivalent to <input type="text">.

 namespaces
use MoonShine\UI\Fields\Text;
 
Text::make('Title')
 namespaces
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>
<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)
placeholder(string $value)
Text::make('Username', 'username')
->placeholder('Enter username')
Text::make('Username', 'username')
->placeholder('Enter username')

Mask

The mask() method allows you to apply a mask to the entered text.

mask(string $mask)
mask(string $mask)

Example usage:

Text::make('Phone', 'phone')
->mask('+7 (999) 999-99-99')
Text::make('Phone', 'phone')
->mask('+7 (999) 999-99-99')

mask mask_dark

Tags

The tags() method transforms the text field into a tag input field.

tags(?int $limit = null)
tags(?int $limit = null)
Text::make('Tags', 'tags')
->tags(5)
Text::make('Tags', 'tags')
->tags(5)

Disable escaping

The unescape() method disables HTML tag escaping in the field value.

Text::make('HTML Content', 'content')
->unescape()
Text::make('HTML Content', 'content')
->unescape()

Extensions

Fields support various extensions to assist with input control.

expansion expansion_dark

Copy

The copy() method adds a button to copy the field value.

copy(string $value = '{{value}}')
copy(string $value = '{{value}}')
Text::make('Token', 'token')
->copy()
Text::make('Token', 'token')
->copy()

Hide value

The eye() method adds a button to show/hide the field value (e.g., for passwords).

Text::make('Password', 'password')
->eye()
Text::make('Password', 'password')
->eye()

Lock

The locked() method adds a lock icon to the field.

Text::make('Protected field', 'protected_field')
->locked()
Text::make('Protected field', 'protected_field')
->locked()

Prefix

The prefix() method adds a prefix to the input field.

prefix(string $ext)
prefix(string $ext)
Text::make('Domain', 'domain')
->prefix('https://')
Text::make('Domain', 'domain')
->prefix('https://')

Suffix

The suffix() method adds a suffix to the input field.

suffix(string $ext)
suffix(string $ext)
Text::make('Domain', 'domain')
->suffix('.com')
Text::make('Domain', 'domain')
->suffix('.com')

PrettyLimit

The prettyLimit() method allows displaying field value in preview mode with limited width. The full text is shown on hover.

prettyLimit(
null|Color|string|Closure $color = null,
null|string|Closure $label = null,
null|int|Closure $limit = null
)
prettyLimit(
null|Color|string|Closure $color = null,
null|string|Closure $label = null,
null|int|Closure $limit = null
)
 namespaces
use MoonShine\Support\Enums\Color;
use MoonShine\UI\Fields\Text;
 
Text::make('Title', 'title')
->prettyLimit(Color::PRIMARY);
 
// with dynamic values
Text::make('Status', 'status')
->prettyLimit(
color: fn($value, $field) => $value === 'active' ? Color::SUCCESS : Color::ERROR,
label: fn($value, $field) => $value === 'active' ? 'Active' : 'Inactive',
limit: 200
);
 namespaces
use MoonShine\Support\Enums\Color;
use MoonShine\UI\Fields\Text;
 
Text::make('Title', 'title')
->prettyLimit(Color::PRIMARY);
 
// with dynamic values
Text::make('Status', 'status')
->prettyLimit(
color: fn($value, $field) => $value === 'active' ? Color::SUCCESS : Color::ERROR,
label: fn($value, $field) => $value === 'active' ? 'Active' : 'Inactive',
limit: 200
);

Learn more about the component in the PrettyLimit section.

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()
Text::make('Name')
->updateOnPreview()
->locked()