Text

# Make

The text field includes all the basic methods.

use MoonShine\Fields\Text;
 
//...
 
public function fields(): array
{
return [
Text::make('Title')
];
}
 
//...

# Default value

You can use the default() method if you need to specify a default value for a field.

default(mixed $default)
use MoonShine\Fields\Text;
 
//...
 
public function fields(): array
{
return [
Text::make('Title')
->default('-')
];
}
 
//...

# Only for reading

If the field is read-only, then you must use the readonly() method.

readonly(Closure|bool|null $condition = null)
use MoonShine\Fields\Text;
 
//...
 
public function fields(): array
{
return [
Text::make('Title')
->readonly()
];
}
 
//...

# Mask

The mask() method is used to add a mask to a field.

mask(string $mask)
use MoonShine\Fields\Text;
 
//...
 
public function fields(): array
{
return [
Text::make('Title')
->mask('7 (999) 999-99-99')
];
}
 
//...

# Placeholder

The placeholder() method allows you to set placeholder attribute on the field.

placeholder(string $value)
use MoonShine\Fields\Text;
 
//...
 
public function fields(): array
{
return [
Text::make('Country', 'country')
->nullable()
->placeholder('Country')
];
}
 
//...

# Extensions

There are several extensions available for the Text field:

+ ability to copy a value using a button

copy()

+ lock with change blocking

locked()

+ disable value display

eye()

+ format hint

expansion(string $ext)
use MoonShine\Fields\Text;
 
//...
 
public function fields(): array
{
return [
Text::make('Title')
->copy()
->locked()
->expansion('kg')
->eye()
];
}
 
//...

The copy method uses the Clipboard API which is only available for HTTPS or localhost

You can use custom extensions, To do this, they must be added to the field via the extension() method.

extension(InputExtension $extension)
use MoonShine\Fields\Text;
 
//...
 
public function fields(): array
{
return [
Text::make('Title')
->extension(new InputCustomExtension())
];
}
 
//...

# Tags

The tags() method allows you to enter data in the form of tags.

tags(?int $limit = null)
  • $limit - number of available tags, unlimited by default.
use MoonShine\Fields\Text;
 
//...
 
public function fields(): array
{
return [
Text::make('Keywords')
->tags()
];
}
 
//...

# Editing in preview

The updateOnPreview() method allows you to edit the Text field in preview mode.

updateOnPreview(?Closure $url = null, ?ResourceContract $resource = null, mixed $condition = null)
  • $url - url for asynchronous request processing,
  • $resource - model resource referenced by the relationship,
  • $condition - method run condition.

The settings are not required and must be passed if the field is running out of resource.

use MoonShine\Fields\Text;
 
//...
 
public function fields(): array
{
return [
Text::make(Country)
->updateOnPreview()
];
}
 
//...