EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

boolean fields are rendered without form-switch class on "add new" action

Open pfpro opened this issue 2 years ago • 5 comments

on the "add new" action, boolean fields are now rendered without the form-switch class. only normal checkboxes are displayed.

image

Does anyone have a similar problem?

pfpro avatar Nov 20 '24 11:11 pfpro

Yes, I have the same problem on the latest version of EasyAdmin. I've also attempted to run php bin/console asset:install again to fix other issues, but this prevails with me.

bytes-max avatar Nov 20 '24 12:11 bytes-max

@javiereguiluz just a heads up, as this prevails currently in our installations. Do you have an idea? :thinking:

bytes-max avatar Dec 03 '24 10:12 bytes-max

Hey, found the problem, it's in easyadmin-bundle/src/Field/Configurator/BooleanConfigurator.php

// this happens when processing fields not for a specific entity (e.g. when
// rendering the filters from the 'index' page)
if (null === $entityDto->getPrimaryKeyValue()) {
    $field->setCustomOption(BooleanField::OPTION_RENDER_AS_SWITCH, false);
    return;
}

This is what breaks it. Just updated and saw it happening. The problem is the specific check for getPrimaryKeyValue. I tested by commenting it and it works, doesn't break the filters or anything else I saw.

My problem is when the entity is part of a collection in another entity.

The fix is easy but I'm not sure why was this piece of code added.

kadiiski avatar Dec 09 '24 14:12 kadiiski

also see https://github.com/EasyCorp/EasyAdminBundle/issues/6647

pfpro avatar Dec 13 '24 13:12 pfpro

@pfpro yeah, same issue, indeed. 👍

kadiiski avatar Dec 13 '24 13:12 kadiiski