Use input-groups in easy-admin 3

427 Views Asked by At

I'm trying to use input-groups in easy-admin3, as much as I search the net, I can't find any ideas?

My question is if it is possible to add it by specifying the config from the configureFields method as the "setFormTypeOption" is used to specify certain properties and not have to create a file file.html.twig for this

      $emailFields = TextField::new('email')->setFormTypeOption("attr.maxlength", 100);

      if($pageName==Crud::PAGE_EDIT || $pageName==Crud::PAGE_NEW){
        $tagFields
          ->setFormTypeOption("attr.class", 'check-field')
          ->setFormTypeOption("attr.style", "text-transform:uppercase")

          // something like that
          //->setFormTypeOption("attr.input-group", "@example.com")
      }

To get something like that. enter image description here

1

There are 1 best solutions below

0
On

I believe you can add a class or other attributes like this

TextareaField::new('value')->setFormTypeOptions([
        'attr' => [
            'data-ckeditor' => 'true',
            'class' => 'form-control',
        ],
    ])
    ;

But what you want to do needs to work with the form theme template:

To form_theme.html.twig

{% block value_widget -%}
    {%- if symbol -%}
        <div class="input-group">
            {{- block('form_widget_simple') -}}
            <div class="input-group-append">
                <span class="input-group-text">{{ symbol|default('%') }}</span>
            </div>
        </div>
    {%- else -%}
        {{- block('form_widget_simple') -}}
    {%- endif -%}
{%- endblock %}

To Dashboard controller

public function configureCrud(): Crud
{
    return Crud::new()
        ->addFormTheme('form_theme.html.twig')
    ;
}

Finally to your field

TextField::new('value')
    ->setFormTypeOptions([
        'block_name' => 'value',
    ])
    ;