EasyCorp / EasyAdminBundle

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

Bool Toggle on crud controller index error #5132

Open 3PSY0N opened 2 years ago

3PSY0N commented 2 years ago

Hello, I have a problem with my application in production. When I want to click on the boolean toggle on the crud controller index, an ajax request (PATCH) is supposed to be sent. But I have an error, the button becomes gray, nothing sent in DB, and the JS have an error.

in the crud controller i have

public function configureFields(string $pageName): iterable
  {
    return [
    //...
      BooleanField::new('prop'),
    ];
}

In the browser console i have this error

Uncaught (in promise) TypeError: can't access property "classList", e.closest(...) is null
e https://mywebsite.com/bundles/easyadmin/app.js:2
createToggleFields https://mywebsite.com/bundles/easyadmin/app.js:2
promise callback*createToggleFields/</< https://mywebsite.com/bundles/easyadmin/app.js:2
createToggleFields https://mywebsite.com/bundles/easyadmin/app.js:2
createToggleFields https://mywebsite.com/bundles/easyadmin/app.js:2
<anonymous> https://mywebsite.com/bundles/easyadmin/app.js:2
EventListener.handleEvent* https://mywebsite.com/bundles/easyadmin/app.js:2
<anonymous> https://mywebsite.com/bundles/easyadmin/app.js:2
<anonymous> https://mywebsite.com/bundles/easyadmin/app.js:2
app.js:2:152045
e https://mywebsite.com/bundles/easyadmin/app.js:2
createToggleFields https://mywebsite.com/bundles/easyadmin/app.js:2
(Asynchrone : promise callback)
createToggleFields https://mywebsite.com/bundles/easyadmin/app.js:2
(Asynchrone : EventListener.handleEvent)
createToggleFields https://mywebsite.com/bundles/easyadmin/app.js:2
forEach self-hosted:167
createToggleFields https://mywebsite.com/bundles/easyadmin/app.js:2
<anonyme> https://mywebsite.com/bundles/easyadmin/app.js:2
(Asynchrone : EventListener.handleEvent)
<anonyme> https://mywebsite.com/bundles/easyadmin/app.js:2
<anonyme> https://mywebsite.com/bundles/easyadmin/app.js:2
<anonyme> https://mywebsite.com/bundles/easyadmin/app.js:2

This error happens only in production, locally everything works as expected.

Config details: Local Prod
HTTPD PHP Built-in Apache
PHP 8.0 Same
Symfony 6.0.6 Same
EasyAdmin 4.0.9 Same

What i'm supposed to do? Thank you

dwd-akira commented 2 years ago

Hello, i checked and i have the same problem but after refresh the page, boolean have the good value.

PHP 8.1.3 Symfony 5.4.4 EasyAdmin 4.0.7

dwd-akira commented 2 years ago

I found the problem, because i overrided function edit and fix return (with KeyValueStore) since deprecation.

Ajax response : App\Controller\Admin\Crud\AdminCrudController::edit(): Return value must be of type EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore, Symfony\Component\HttpFoundation\Response returned

I added Response on return

public function edit(AdminContext $context): KeyValueStore|Response

If it's not working for you, look the ajax response in the browser console.

3PSY0N commented 2 years ago

I found the problem, because i overrided function edit and fix return (with KeyValueStore) since deprecation.

Ajax response : App\Controller\Admin\Crud\AdminCrudController::edit(): Return value must be of type EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore, Symfony\Component\HttpFoundation\Response returned

I added Response on return

public function edit(AdminContext $context): KeyValueStore|Response

If it's not working for you, look the ajax response in the browser console.

Hi thank you for reply!

Nope, still not working, i still have the error in console and PATCH failed. it's weird because it's working on local server (WSL app launched with symfony server:start) and not on prod server.

I precise, it fail only in Index view. not in the Edit view.

Thanks

dwd-akira commented 2 years ago

And no ajax call in the Network console ?

3PSY0N commented 2 years ago

Nope, the PATCH request send no response =/

dwd-akira commented 2 years ago

It's a new install or the problem appears after an update ?

3PSY0N commented 2 years ago

It's an update, i started my project with EA 3. But i don't understand why in local server i have no error (v4.0.9) and in production i have this error (v4.0.9) too. All my project is up to date in local/prod. so i don't understand where is the issue.

fabienlem commented 2 years ago

Same problem here.

fabienlem commented 2 years ago

There is further information here but not sure on how to diagnose issue with toggle switch:

https://stackoverflow.com/questions/58215104/whats-the-neterr-http2-protocol-error-about

Here is my console output:

image

I guess the "classList" error is a consequence of the net::ERR_HTTP2_PROTOCOL_ERROR error.

AlexaneTrubert commented 6 months ago

Same issue here, has anyone solved the problem ?