EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

App.js error when expanded => true on ChoiceField

Open Dumorya opened this issue 4 years ago • 4 comments

Describe the bug When 'expanded' => true, the following error appears in the console:

app.js:2 Uncaught TypeError: Cannot read properties of undefined (reading 'length') at e.S (app.js:2) at e.value (app.js:2) at app.js:2 at NodeList.forEach () at Object.createAutoCompleteFields (app.js:2) at HTMLDocument. (app.js:2)

If 'expanded' => false, no error is showing up.

To Reproduce EasyAdmin version used: 3.5.17

Set a ChoiceField like this one in a CrudController:

ChoiceField::new('bottling')->hideOnIndex() ->allowMultipleChoices(false) ->setFormTypeOptions([ 'expanded' => true, 'multiple' => false, 'placeholder' => false ]) ->setChoices([ 'Yes' => true, 'No' => false ]),

Please go on the admin form page of this Crud, and check the console.

(OPTIONAL) Additional context

Dumorya avatar Jan 04 '22 14:01 Dumorya

Hi, same issue in 4.6.1 version with an AssociationField

to reproduce in a crudController :

        yield AssociationField::new('associationField')
            ->setFormTypeOptions([
                'expanded'  => true,
            ])
        ;

console.log eror :

caught TypeError: Cannot read properties of undefined (reading 'trim')
    at app.3f8ee14e.js:2:93762
    at ct (app.3f8ee14e.js:2:93910)
    at new ut (app.3f8ee14e.js:2:95832)
    at t.O (app.3f8ee14e.js:2:145823)
    at t.value (app.3f8ee14e.js:2:145087)
    at app.3f8ee14e.js:2:155488
    at NodeList.forEach (<anonymous>)
    at t.it (app.3f8ee14e.js:2:155465)
    at new t (app.3f8ee14e.js:2:149274)
    at HTMLDocument.<anonymous> (app.3f8ee14e.js:2:148601)

ceponcet avatar Apr 20 '23 05:04 ceponcet

Quick and ugly workaround for AssociationField, Just duplicate vendor/easycorp/easyadmin-bundle/src/Field/AssociationField.php to src/Admin\Field/ExpandedAssociationField.php

        yield ExpandedAssociationField::new('associationField') 
            ->setFormTypeOptions([
                'expanded'  => true,
                'class'   => UsedEntity::class, // Need to specify the entity!
            ]);

@Dumorya, it's works with ChoiceFIeld too but you need to specify the choices in setFormTypeOptions() method and not in setChoices

 yield ExpandedChoiceField::new('uais')->onlyOnForms()
         //  ->setChoices($choices) // do not work
            ->setFormTypeOptions([
               'placeholder'=> false,
                'choices'   => $choices, // <= set choices here
                'expanded'  => true,
            ])
        ;
```The

The javascript of the page executes well.

ceponcet avatar Apr 20 '23 06:04 ceponcet

See #5705

ksn135 avatar Apr 20 '23 06:04 ksn135

Just adding ->setCustomOption('widget', null) will resolve this issue👍

See here: https://github.com/EasyCorp/EasyAdminBundle/blob/v4.10.2/src/Field/Configurator/AssociationConfigurator.php#L91-L93 https://github.com/EasyCorp/EasyAdminBundle/blob/v4.10.2/src/Field/Configurator/ChoiceConfigurator.php#L102-L105

ttskch avatar Jun 13 '24 22:06 ttskch

This issue has been automatically closed as part of our end-of-year repository maintenance. As an open-source project with limited resources, we need to focus our efforts on the most current and impactful issues. If this feature or bug is still relevant to you, please create a new issue. For bugs, include a detailed reproducer, and for features, provide a clear explanation of your request. Thank you for your understanding and for supporting our project!

javiereguiluz avatar Dec 31 '24 08:12 javiereguiluz