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">.

use MoonShine\UI\Fields\Text;
 
Text::make('Title')
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>

mask mask_dark

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

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

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