Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have a form in which some select elements are ajax elements that trigger a full reload of the form. When I look at the reloaded form, all the links, e.g. for the pager I have on there and for the tablesort as well, are rewritten so they point to system/ajax, which breaks functionality off course.
Comment | File | Size | Author |
---|---|---|---|
#7 | tests_pager_and_tablesort_links_in_ajax_forms-1181370-7.patch | 5.18 KB | pbuyle |
Comments
Comment #1
sunIn order to call this a bug report, clear steps to reproduce the bug are required.
Comment #2
daften CreditAttribution: daften commentedAre these steps enough. If necessary, I can post the code, but unfortunately, it wouldn't work, since it works on an external database which contains proprietary data.
This issue is because in tablesort.inc the links in the table are created based on the q parameter. This is in basis a good assumption, however, in this specific case it throws errors.
And honestly, i have no idea of a decent workaround, except maybe by allowing an option to be passed to tablesort to give the path.
Comment #3
sunThat sounds sufficient for me. Next step would be to convert those steps into a test, to confirm the bug exists, and prevent it from being re-introduced after it has been fixed.
Comment #4
daften CreditAttribution: daften commentedI will (try to) look into that the coming days.
Are you sure this applies to the ajax system, since the URL's are written in tablesort.inc ? It seems this might not be solvable there.
Comment #5
daften CreditAttribution: daften commentedI'm looking into it, but this is the first time I'm writing tests for drupal, so It's gonna be some trial-and-error (and I don't have much spare time left). The configuration part I get, but can you give me a hint if there are functions to tests for specific links in the output or something similar (so i don't have to test the entire output specifically)?
Comment #6
pbuyle CreditAttribution: pbuyle commentedsubscribe
Comment #7
pbuyle CreditAttribution: pbuyle commentedHere is a patch to add tests for pager and tablesort links in ajax enabled forms. As demonstrated by these tests, if
theme('pager', ...)
andtheme('table', ...)
are called from the form builder functions, the produced links correctly point to the page URL (and not system/ajax). But if the pager or table are returned as render arrays (ie.array('#theme' => 'pager', ...)
andarray('#theme' => 'table', ...)
), the links point to system/ajax.Comment #8
khacnhat CreditAttribution: khacnhat commentedsubcribe
Comment #9
Kvitz CreditAttribution: Kvitz commentedI'm experiencing this problem too in drupal 7.12. I'm trying to build a tableselect using theme() function and #markup, as in the patch above, and it does seem to solve the system/ajax problem when an ajax action is triggered, but I'm not being able to change the table in the ajax function afterwards nor to use the pager. Are there any resources on how to build tableselects using theme function to solve the system/ajax problem?
Comment #10
pbuyle CreditAttribution: pbuyle commented@Kvitz: The patch in #7 only add tests to demonstrate the issue, it does not solve it.
The workaround, if I remember correctly, is the render the pager in the form builder. So instead of something modern like
You do it old-style and call
theme('pager')
pager to generate the content of amarkup
elementEdit: Oups, I misread your post. Sorry, AFAIK, there is no documentation or resource to solve this. I made some ugly JavaScript hacks to work around this and rewrite the links but nothing worth sharing (as it lacks documentation and is really tied to a specific form).
Comment #11
jbeuckm CreditAttribution: jbeuckm commentedsubscribe
Comment #12
lmdoom CreditAttribution: lmdoom commentedI've managed to solve it next way:
$_GET['q'] param is used by pager to get current page path. So I set page path I need.
I hope, it helps someone else.
Comment #13
manuel.hidalgo CreditAttribution: manuel.hidalgo commentedHola recien tengo un problema con el siguiente error:
An error occurred while attempting to process /es/system/ajax: this._each is not a function
Alguien ha resuelto esto?
Comment #14
Kvitz CreditAttribution: Kvitz commentedThanks Leonid.adcillc. This has indeed improved my problem. It now points to the right place. My only problem now is dealing with multiple paged tables in the same drupal form.
Comment #15
pinin4fjords CreditAttribution: pinin4fjords commentedI'm seeing this issue in 7.20. In my case I worked around it by saving the value from GET at the first view of my form:
... and restoring it later when necessary (in my case immediately before a call to views_embed_view() after some ajax):
Comment #16
4fs CreditAttribution: 4fs commentedHi, Any progress on this issue. Seems to be a deal breaker for my ubercart site. How could I use the info above to place a quick fix in place. Where does the code go etc. Thank you.
Comment #17
learnbydrop CreditAttribution: learnbydrop commentedAjax Pagination error in the form, any solution for this issue...?
Comment #18
mondrakePlease, leave this issue to the 8.x-dev version, at the moment. Bugs are first addressed in the developing version (Drupal 8 currently), and only when solved there, backported to previous versions if possible. Changing version will take it away from the radar of the core developers. Thanks.
I can confirm that in D8 this is still the case:
Comment #19
mondrakeWorking on a fix for #2182555: On Ajax-enabled forms with a pager, pager is disappearing on form validation error and on Ajax form reload, I think now I have clear why this happens, at least in D8.
At the moment we do not even have pagers on Ajax reload, so I believe #2182555: On Ajax-enabled forms with a pager, pager is disappearing on form validation error and on Ajax form reload needs to be fixed first. If the fix there gets accepted as a solution, we could use a similar model here, i.e. store (parts of) the current request in the cached $form_state, and during Ajax reload temporarily swap the Ajax route request with the original (cached) one, for the part of the Ajax processing that re-renders the form.
Comment #20
kevinquillen CreditAttribution: kevinquillen commentedYes, this is an issue. You can see this typically when you have triggered an AJAX command, execute some code like drupal_get_form, and return it in a modal. When executing from the AJAX callback, the path is almost always system/ajax because it is handling the command callback from the AJAX framework (in 7). Thus any dynamic paths, like pagers, break when replaced, with the wrong URLs. I am looking at this issue on my screen right now in a Drupal Commerce site I am building.
Comment #21
mondrakeThis issue was fixed for D8 by #2263569: Bypass form caching by default for forms using #ajax., by POSTing AJAX forms back to the form's URL and identifying differently the need to process them via AJAX. I have no idea if similar approach could be taken here, but this is now a D7 only issue.
Comment #22
czigor CreditAttribution: czigor at Liip commentedAs a quick fix I overrode theme_pager_link() to set the url of my AJAX-loaded pager to the page url instead of $_GET['q'] (which was system/ajax).
Comment #23
Ali yah CreditAttribution: Ali yah commentedIs there anyway I can distinguished the first view/load of the form not triggered by a callback function?
Comment #24
wuinfo - Bill Wu CreditAttribution: wuinfo - Bill Wu for Wulei Info Technology Solutions commentedNice we get it solved on D8, another reason to use D8. :)
Comment #25
JayKandari#12 for D7 !!
Comment #26
amit0212 CreditAttribution: amit0212 as a volunteer and at Iksula commentedComment #27
joegl CreditAttribution: joegl commentedI don't think this was fixed for 8:
#2504115: AJAX forms should submit to $form['#action'] instead of <current>
#2504709: Prevent _wrapper_format and ajax_form parameters from bleeding through to generated URLs
Comment #28
joegl CreditAttribution: joegl commentedThis definitely was not fixed in 8, unless I'm doing something wrong. My tablesort links are all broken when I render a table in an AJAX callback.
Comment #29
joegl CreditAttribution: joegl commentedComment #30
joegl CreditAttribution: joegl commented