EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Bool Toggle on crud controller index error

Open 3PSY0N opened this issue 3 years ago • 10 comments

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

3PSY0N avatar Mar 19 '22 06:03 3PSY0N

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 avatar Mar 19 '22 18:03 dwd-akira

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.

dwd-akira avatar Mar 19 '22 18:03 dwd-akira

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

3PSY0N avatar Mar 21 '22 00:03 3PSY0N

And no ajax call in the Network console ?

dwd-akira avatar Mar 21 '22 17:03 dwd-akira

Nope, the PATCH request send no response =/

3PSY0N avatar Mar 22 '22 11:03 3PSY0N

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

dwd-akira avatar Mar 22 '22 23:03 dwd-akira

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.

3PSY0N avatar Mar 23 '22 22:03 3PSY0N

Same problem here.

fabienlem avatar Mar 26 '22 10:03 fabienlem

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.

fabienlem avatar Apr 07 '22 18:04 fabienlem

Same issue here, has anyone solved the problem ?

AlexaneTrubert avatar Apr 07 '24 21:04 AlexaneTrubert