Skip to content

EasyAdmin Text Field

Edit this page

This field is used to represent any kind of short text content. For long text contents, use TextareaField, TextEditorField or CodeEditorField.

In form pages (edit and new) it looks like this:

Default style of EasyAdmin text field

Tip

If the text content represents some special kind of data (e.g. a telephone number or an email address) there are many other specific EasyAdmin fields that you can use: AvatarField, ColorField, CountryField, CurrencyField, EmailField, IdField, ImageField, LanguageField, LocaleField, SlugField, TelephoneField, TimezoneField and UrlField.

Basic Information

  • PHP Class: EasyCorp\Bundle\EasyAdminBundle\Field\TextField
  • Doctrine DBAL Type used to store this value: string or ascii_string
  • Symfony Form Type used to render the field: TextType
  • Rendered as:

    1
    <input type="text" value="...">

Options

renderAsHtml

In read-only pages (index and detail), text contents are escaped (using htmlspecialchars()) before displaying them. If you have some field where you want to render HTML tags instead of escaping them, add this option:

1
yield TextField::new('...')->renderAsHtml();

This option takes precedence over stripTags(): when both are enabled, the contents are rendered as HTML and no tag is stripped. EasyAdmin does not sanitize these contents in any way, so only enable this option for contents that you trust.

setMaxLength

By default, text contents are displayed in full in the detail page and are truncated to a maximum of 64 characters in index page. Use this option to set the maximum in both detail and index pages:

1
2
3
4
5
6
7
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;

yield TextField::new('...')->setMaxLength(15);

// inside configureFields() you have access to the current page name
// use it to set different values per page
yield TextField::new('...')->setMaxLength($pageName === Crud::PAGE_DETAIL ? 1024 : 32);

This option only has effect in read-only pages (index and detail). In form pages (new and edit) contents are never truncated in length. See Fields for other ways of configuring fields per page.

Note

This option is ignored when also using the renderAsHtml() option, to avoid truncating contents in the middle of an opened HTML tag.

stripTags

By default, contents are escaped before displaying them. If you prefer, you can strip HTML tags using this option (which internally calls PHP's strip_tags() function):

1
2
// if original contents are <strong>foo</strong>, it only displays foo
yield TextField::new('...')->stripTags();
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version