hyva-themes / magento2-hyva-admin

This module aims to make creating grids and forms in the Magento 2 adminhtml area joyful and fast.
https://hyva-themes.github.io/magento2-hyva-admin/
BSD 3-Clause "New" or "Revised" License
168 stars 39 forks source link

Form Key Error with Pager on List Views #56

Open inavdb opened 3 years ago

inavdb commented 3 years ago

_Error occures in the integernet Slider module (see also internal ticket 17261)

When in a list the number of elements exceeds the standard qty er page (here 20), you cannot edit an element when

  1. You navigate to page 2 and try to open an element.
  2. Switching the rows per page to e.g. 50, trying to edit en element any element

Instead, there's a form key error and you end up on the Dashboard. Editing one of the first 20 elements, when the elements per page = 20 works though.

Vinai commented 3 years ago

disproved: Note to self: it seems the form key changes when an Ajax grid update id done.

Vinai commented 3 years ago

I can see the action URL is configured as <action id="edit" label="Edit" url="*/*/edit" in the grid XML. This configuration doesn't work for Ajax updates of the grid, since they happen through a generic Ajax pager route. Applying the following patch to the grid config should fix the issue:

diff --git a/view/adminhtml/hyva-grid/grid.xml b/view/adminhtml/hyva-grid/grid.xml
index 3b5f08e..b9d8a9f 100644
--- a/view/adminhtml/hyva-grid/grid.xml
+++ b/view/adminhtml/hyva-grid/grid.xml
@@ -17,7 +17,7 @@
         </exclude>
     </columns>
     <actions idColumn="slider_id">
-        <action id="edit" label="Edit" url="*/*/edit" idParam="slider"/>
+        <action id="edit" label="Edit" url="integernet_hyvaslider/slider/edit" idParam="slider"/>
     </actions>
     <navigation>
         <buttons>

I'll leave the issue open for now until you can confirm this fixes the problem.

Vinai commented 3 years ago

I've patched the UrlBuilder during Ajax requests so it will use the original route to build new URLs. Now it will work even without a config change. This will be part of the 1.1.16 release.

lbuchholz commented 3 years ago

@Vinai I can confirm this working for next page navigation, but clicking previous page link won't update anything.

Vinai commented 3 years ago

Thanks for letting me know. I'll look into this, but it will be a while because vacation.

Vinai commented 3 years ago

@lbuchholz I can't reproduce the issue paging through sliders or the test grids. Is there any additional info you can give?

lbuchholz commented 3 years ago

Not really... Use case is hyva_slider with 40+ sliders, page size 20. While I can navigate to next and last page, I cannot go to previous or first page.

Vinai commented 3 years ago

Same behavior when you change to a page size of 10?

lbuchholz commented 3 years ago

Yes.

Vinai commented 3 years ago

I have created 30 sliders, no problem with paging back or forth. Any errors in the console or the ajax response?

Vinai commented 3 years ago

Do you have an answer to my question @lbuchholz? Could you check in the network tab in the devtools if there is some kind of exception or something?

lbuchholz commented 3 years ago

@Vinai Sorry for taking such a long time to respond. I just did a complete reinstall of all modules involved et voilà, works. 🙄 Please close, thank you 👍