EasyCorp / EasyAdminBundle

EasyAdmin is a fast, beautiful and modern admin generator for Symfony applications.
MIT License
4.09k stars 1.03k forks source link

Ability to add html attributes to crud pages #6231

Open KDederichs opened 8 months ago

KDederichs commented 8 months ago

Short description of what this feature will allow to do: Add ability to add html attributes to crud pages.

Example of how to use this feature Would be useful to add Stimulus directives to CRUD pages (data-controller)

    #[\Override] public function configureCrud(Crud $crud): Crud
    {
        $crud->setHtmlAttribute('data-controller', 'clipboard');
        return $crud;
    }
OcB974 commented 7 months ago

Hello,

This solution works for me in my CrudController ( with "easycorp/easyadmin-bundle": "^4.9"):

public function configureCrud(Crud $crud): Crud
{
    $crud->setFormOptions([
        'attr' => [
            'data-controller' => 'coupon' // = <form data-controller="coupon" ...>
        ]
    ]);
 }

public function configureFields(string $pageName): iterable
{
  yield TextField::new('code', 'Code')
      ->setFormTypeOptions([
          'attr' => [
              'data-coupon-target' => 'input'
          ]
      ])
      ->setHelp('<a data-action="coupon#generate" class="btn btn-primary" href="#">Generate random code</a>')
  ;
}
KDederichs commented 7 months ago

Sure I know that works on forms, but there's no form on index to attach the controller to.