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. It does not affect labels, hints, prefixes, or suffixes; use their separate methods.

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

This method controls preview escaping only; it does not disable escaping when applying submitted values. By default, previews follow the global escapes.value setting. Use escape() to explicitly enable preview escaping for a field, even when the global setting is disabled:

 namespaces
use MoonShine\UI\Fields\Text;
 
Text::make('Title')
->escape()
 namespaces
use MoonShine\UI\Fields\Text;
 
Text::make('Title')
->escape()

Escaping on Apply

Submitted strings are escaped before being applied to data by default. To store the original string, disable this behavior for the field with a closure:

 namespaces
use MoonShine\UI\Fields\Text;
 
Text::make('HTML Content', 'content')
->escapeOnApply(fn (Text $field): bool => false)
 namespaces
use MoonShine\UI\Fields\Text;
 
Text::make('HTML Content', 'content')
->escapeOnApply(fn (Text $field): bool => false)

The closure receives the current field and returns whether to escape its submitted value. This setting is independent of preview escaping: the example above stores the original string and keeps the preview escaped unless configured otherwise.

Without a local override, the field follows the global escapes.value_on_apply setting. To enable escaping for one field even when it is disabled globally, call the method without an argument:

 namespaces
use MoonShine\UI\Fields\Text;
 
Text::make('Title')
->escapeOnApply()
 namespaces
use MoonShine\UI\Fields\Text;
 
Text::make('Title')
->escapeOnApply()

Unlike the configurator method, the field method accepts ?Closure $condition = null, not a boolean.

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)

Prefix strings are escaped by default. Use unescapePrefix() for trusted HTML or escapePrefix() to explicitly enable escaping. See Display Escaping.

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)

Suffix strings are escaped by default. Use unescapeSuffix() for trusted HTML or escapeSuffix() to explicitly enable escaping. See Display Escaping.

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()