EasyCorp / EasyAdminBundle

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

Custom field does not load js asset when included in complex CollectionField #6367

Open nevez opened 4 months ago

nevez commented 4 months ago

I defined a DurationField like this:

namespace App\Field;

use App\Form\Type\DurationType;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface;
use EasyCorp\Bundle\EasyAdminBundle\Field\FieldTrait;

final class DurationField implements FieldInterface
{
    use FieldTrait;

    /**
     * @param string|false|null $label
     */
    public static function new(string $propertyName, $label = null): self
    {
        return (new self())
            ->setProperty($propertyName)
            ->setLabel($label)

            // this template is used in 'index' and 'detail' pages
            ->setTemplatePath('field/duration.html.twig')

            // this is used in 'edit' and 'new' pages to edit the field contents
            // you can use your own form types too
            ->setFormType(DurationType::class)

            // these methods allow to define the web assets loaded when the
            // field is displayed in any CRUD page (index/detail/edit/new)
            ->addJsFiles('js/duration-widget.js')
        ;
    }
}

If I set up a direct CRUD link in the menu to CRUD Controller that has a DurationField, the js file is loaded correctly, but when I reference the same entity in a CollectionField of another CRUD Controller, like this:

             CollectionField::new('interventos',false)
                ->setColumns('col-12')
                ->useEntryCrudForm()
                ->setEntryIsComplex()
                ->renderExpanded()
                ->hideOnIndex(),

...the field is displayed with the correct template, but the js file's script tag is not included in the page.

EasyAdmin v4.9.4

javiereguiluz commented 4 months ago

Thanks for reporting this. Please try to debug why/where this error happens. Ideally, you could submit a Pull Request to fix it. But it's fine if you don't do that. But please, debug this error to tell us where exactly is happening so we can fix it. Thanks.