Open Dumorya opened 2 years ago
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)
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.
See #5705
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
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