Summary
When using 'Exposed form in block' together with 'Ajax enabled' - the ajax no longer works.
Steps to recreate
Create a new 'Page' view that displays node titles.
Expose the 'Published' field as a filter.
Ensure 'Ajax' is enabled on the View
Test - notice that changing the filter updates the view using ajax: correct
Edit the View and enable 'Exposed form in block'
Place the block on the View page
Test - notice that changing the filter does not update the view using ajax any more
Issue introduced
The issue was introduced in commit: http://cgit.drupalcode.org/views/commit/?id=710a536
This changes the behaviour of the ajax_view.js file and no longer correctly applies ajax to exposed forms in blocks
Reverting this change fixes the issue (but there is probably a better approach!).
Comments
Comment #1
jkingsnorth commentedComment #2
rocxa commented+1
Comment #3
dawehnerIt would be great to find an actual solution ... this code was committed to solve a real existing issue, so just reverting is not the best solution.
Do you mind having a look why it doesn't work? Thank you!
Comment #4
jkingsnorth commentedHi dawehner. There was no issue# against the commit, so I'm not sure what the problem it solves is. Without knowing that I might be putting together a fix that re-introduces the same problem again.
I'll give it a shot anyway, but do you know what the original issue was?
Comment #5
othermachines commentedDuplicate: Issue #2425661: Ajax output with exposed filters stopped working after 7.x-3.10 update
Comment #6
dawehnerI don't really know, honestly :(
Comment #7
Chmit commentedYou should replace
this.$view.children('.view-filters').children('form');by
this.$exposed_form = this.$view.find('.view-filters').children('form');In custom views, view-filters class can be not directly a child
Comment #8
jkingsnorth commentedHi Chmit, the fix you propose does not work for us. Ajax still does not seem to work on Views with their exposed form in a block.
This is because the class '.view-filters' is not present.
Comment #9
Chmit commentedOk, I forgot I wrote these class in tpl.php..... We should replace .view-filters by a class always displayed with a selector always used.
Comment #10
jkingsnorth commentedNo worries, thanks for the idea though Chmit.
Comment #11
Tyler the Creator commentedI really don't think that there was an issue with how the exposed filters were being targeted before the update.
The only problem with how it was before:
this.$exposed_form = $('form#views-exposed-form-'+ settings.view_name.replace(/_/g, '-') + '-' + settings.view_display_id.replace(/_/g, '-'));was probably the worry that the form id was going to change at some point to not match the view_name + view_display_id approach.
Currently looking into a way to maybe pass the view's dom_id to the exposed filter form as a class... or some other solution.
It's a little silly that this update wasn't even fully tested though. It seems like the committer just decided to change it on a whim.
Comment #12
Tyler the Creator commentedHere's a patch to add a dom_id class to the exposed form and target that class instead of the View's child ".view-filters"
Comment #16
Tyler the Creator commentedRe-diffed the patch, hopefully this one tests well.
Comment #18
Tyler the Creator commentedI guess
Views 7.x-3.xis failing testing? I have no idea what the problem is... sorry :\Comment #21
clfer commentedHi Tyler
I join you on your bug diagnostic and resolution.
Here should be your corrected patch (it seems that there was some commit since you made it, that's why it fails testing)
Comment #22
clfer commentedComment #24
clfer commentedOk mine is incomplete and also fail testing so i'll just hide it
Sorry for the intervention
Comment #25
Tyler the Creator commentedComment #27
jkingsnorth commentedHi Tyler, you might need to re-roll the patch and re-add it to the issue, otherwise the latest (incomplete) patch will continue to get tested?
Comment #28
Tyler the Creator commentedMy bad, sorry for the spam.
I actually just found this test page: https://qa.drupal.org/pifr/test/27332 so it does seem like 7.x-3.x is the thing that is broken since the last commit on the 13th and my patch should be fine (since it only adds/changes 2 lines). Anyone willing to try it out even though the automated tester is having a rough time?
Comment #29
jkingsnorth commentedWill do tomorrow Tyler, sorry not to have done sooner.
Comment #30
drikc commentedAre we going to keep the "strict" select as follow:
this.$exposed_form = this.$view.children('.view-filters').children('form');This mean that the above wont be able to select if one want to alter the exposed form by adding a wrapper!...
Could we soften this selector with something like:
this.$exposed_form = this.$view.find('.view-filters form');Comment #31
jkingsnorth commentedHi drikc, this was suggested above. Unfortunately the class .view-filters is not always present on the form, as mentioned in #8.
However the patch in #16 works for me, and seems like a good approach? Could you re-submit the patch Tyler, to bring it to the latest spot in the queue?
One more review for RTBC?
Comment #32
drikc commentedYes, just tried the patch in #16 and works for me also.
Comment #33
jkingsnorth commentedMarking #16 as RTBC then
Comment #34
chase. commentedWhen the exposed form (block) is shown on a site without the view:
This doesn't exactly have to do with AJAX, but was introduced with the patch from #16
Comment #35
Tyler the Creator commentedAhhh, in patch #12 I had the dom_id code inside the if statement checking to see if ajax is being used. For some reason in #16 I moved it out. I guess the form isn't getting the view's dom_id if ajax isn't being used.
This new patch adds that code back in to the if statement.
Comment #36
chase. commentedWorking like before, just without the notice for me!
Comment #37
kuangshi.yan commentedI had the same issue after the 7.x-3.10 update, the patch #35 works for me!
Comment #38
jkingsnorth commentedPatch applies OK on simplytest.me, and still seems to work =] Couldn't detect any php notices. RTBC.
Comment #39
justindodge commented#35 worked well for me, no php notices - looks good.
Comment #40
thulenb commented#35 works for me, too.
Comment #41
nicholasthompson#35 works for me too
Comment #42
erichomanchuk commentedI am still having issues. I'm using panels to display a panel view with an exposed form block and views is doing some rather strange behaviours.
Basically Im filter articles by a taxonomy using ajax. I add the panel view to the page and the exposed filters to the page. If I have the exposed filters before the panel view the ajax update does not work If I move the exposed filters after the panel view then ajax works. debugging the view in views_exposed_form shows me it runs twice. When the exposed filters are after the panel view there is a dom_id in the first view object when the filters are before the view there is no dom_id in either $view object so no class is added.
Anyone else experiencing issues with views update 7.10 and panels.
Debugging the views_exposed_form $view object in 7.8 and it is the same if the filters are before the panel view there is no dom_id in the either of the $view objects so adding it as a class is not working.
Comment #43
jkingsnorth commentedMarked #2433537: Ajax broken when updating to 3.10 as a duplicate.
Comment #44
Tyler the Creator commentedChanging this to Needs work until we figure out a solution that works with Panels. With the dom_id solution, I thought that the exposed form would have the entire view object that it belonged to, but that's only the case when the view is pre-rendered before the form... not after.
Comment #45
mustanggb commentedComment #46
vaibhav571 commentedThe issue can be fixed by this patch
Comment #47
Tyler the Creator commentedWhile reverting the commit that broke this in the first place in #46 does fix the problem, it was changed to allow for a "safer way of finding the exposed form". #46 is a good stop gap but I still think that there could be a better way to fix the entire problem.
Comment #48
vaibhav571 commentedUsing other solutions may fix the problem but they will still fail if using the filters inside quick tabs. Till now this the only that I could find to get the things work.
Comment #49
vaibhav571 commentedComment #50
jkingsnorth commentedAs dawehner also said near the top then, just reverting the commit probably isn't the best solution.
Comment #51
jkingsnorth commentedMarked #2449531: Exposed Filter Ajax broken as a duplicate - but there is a possible patch in that thread up for review
Comment #52
FiLeVeR10 commentedHere's the patch from #2449531 . I did not write this code, @ben.bunk posted it on that issue, I just made it a patch to post here to hopefully move along this being added into views so I can get my exposed filters with ajax back.
@John.K said there that the patch should go here.
Comment #53
jkingsnorth commentedI'm not sure the code in #52 is the right approach, since it still re-implements the code that was originally removed. Falling back to this code is probably just as undesirable as using it in the first place.
So I'm going to set this as needs work again.
#35 looks promising but does not work with Panels (see #42).
This issue also has implications for custom templates as described in #2320661: Make js selector for finding exposed forms for AJAX more forgiving.
Comment #54
FiLeVeR10 commented@John.K is the problem with panels a views vs. panels issue, or a dom loading order issue for exposed filters in general; where if the form loads before the view is in the dom it's unable to attach?
Comment #55
Tyler the Creator commented@FiLeVeR10 The problem is a dom loading order issue. The exposed filters form loads and the view does not go through its pre_execute function (where dom_id is set) until the view itself is loaded. Due to that issue I'm not sure that my patch at #35 is the correct direction to take in fixing this problem... because moving where the dom_id is set or pre_executing the view on the exposed filters form would not be ideal.
I'd like to get this fixed asap, but I haven't had any more time to look into it.
Comment #56
FiLeVeR10 commented@tyler ok, I'll check it out tonight and see if I can put together something to work with that will cover both bases.
Comment #57
ParisLiakos commented#52 works for me, using it w panels..
maybe it should be commited as intermediate step, since, this is a regression?
Comment #58
mustanggb commentedMarked #1222762: Exposed filters in blocks do not use ajax, redirect to front or views page as a duplicate.
Comment #59
FiLeVeR10 commentedI did recreate the issue and look into a few ways around it.
I'm trying to find a good way to make it run after both elements are in the dom.
I'll try to get a working patch in soon.
Comment #60
plachWhat about this? It preserves the "intent" of the current code but only as a fallback, since the
.view-filtersclass may no longer be there if markup was altered. By default it uses a plain class to identify the exposed form. I tried to figure out why the class is commented out in HEAD, but git blame does not help.Comment #61
FiLeVeR10 commentedI feel like using .find() is the wrong approach altogether, since it only checks inside of that object for the element.
Isn't the whole point of the id on the form to tie it to the view, why isn't it being used anymore?
Comment #62
plachI don't know why the id is no longer used, but using a class this way is the closest thing I can think of.
Comment #63
mustanggb commentedPerhaps exposed filters need their own dom_id
Comment #64
dawehnerAsked merlinofchaos on IRC
Comment #65
zmove commented#52 works for me
#60 not
Comment #66
k.skarlatos commented#52 works for me, RTBC
Comment #67
mustanggb commentedAs per #53
Comment #68
merlinofchaos commentedI think there was a problem with views within views or multiple of the same view on the page that I was running into when using a modified version of the entity reference module, and this commit fixed that. If that helps.
Comment #69
jkingsnorth commentedThis sounds like more of an edge case than using an exposed form in a block with AJAX. But it would still be good to find an approach that fixed all cases of this, rather than just reverting to the original code.
Comment #70
FiLeVeR10 commentedWell .find()'s never going to work if the exposed filters are not in the main view container, so reverting it to be selected by id instead seems like a good option. Is there a better way to target the exposed form when it's outside of the view container?
For the DOM loading issue, does it only affect panels or does it affect blocks with exposed filters being loading after a view in the dom as well.
If it's just panels, wouldn't that make it a different issue?
Comment #71
Tyler the Creator commentedIt affects every instance where the external exposed filters form is loaded before the view display I believe.
Comment #72
Renee S commented#35 worked for me, with Panels. #52 did not.
Comment #73
nedjoIndeed, on my testing, the latest patch fixes AJAX in a block display that includes an exposed filter and on a page display that includes an exposed filter, but when I expose the page display's form in a block, as indicated AJAX isn't applied.
Comment #74
rooby commentedThere really should be a unique class or ID based on the view name and display that can be directly targeted.
Anything else is really asking for future problems IMO.
Comment #75
recrit commentedSee #1809958: Views with exposed filter (ajax enabled) inside modal window (ctools) - That fix has been committed and addresses this issue using the form id which is set in views_exposed_form().
Comment #76
thulenb commentedUntil this bug is fixed what do you guys do in the meanwhile. I can't update Views due to this bug but the status reports keeps telling me "urgent security update" for Views. Is waiting the right way for a non-coder like me?
Comment #77
mustanggb commented@ThuleNB
I'm running the latest stable version (3.11 at the time of writing), but have just manually reverted the commit that "broke things".
i.e. Changed this one line back to what it was before: http://cgit.drupalcode.org/views/commit/?id=710a5368c0f71100aaa51de01695...
As per #68 this wasn't a security fix, but rather a bug fix for a rare occurrence, so if you're not using that use-case then everything should be fine.
Comment #78
rooby commentedI'm using the patch from #52.
For my site it fixes the problem and doesn't cause any issues.
Comment #79
thulenb commentedok thanks, that helps :-)
Comment #80
nedjoAs noted in #75, this issue was fixed in #1809958: Views with exposed filter (ajax enabled) inside modal window (ctools) by reverting the commit that introduced the bug (while addressing a different bug).
Closing as a duplicate.
For those wanting this fix before the next stable release of Views, one way is to apply the patch that was applied. See for example the instructions for manually applying a patch.
Comment #81
alauddin commentedCan confirm patch from #52 works ..but is no longer needed.
The current 7.x-3.11+14-dev has another patch committed that solves this issue.
https://www.drupal.org/node/1809958#comment-9905847
Comment #82
W.M. commentedReverting to the original code solved the issue for me.
Comment #83
jelo commentedWith Views 7.x-3.13 the exposed forms work for me again, with and without panels. However, it only works as long as the exposed form is only included once in the page.
There are a number of issues with views (I, II, III) where users try to separate these options: sort, search and filter to improve the user experience. The only workarounds so far have been to suggest re-using the same exposed form multiple times on the page and hiding elements with CSS in each of those forms to generate one form dedicated for search, one for filters, one for sorting. Then each form can be placed independently in the UI.
With panels it is very easy to place the exposed form multiple times on the same page. As soon as the same form is added a second time, AJAX stops working though, I assume because the form ID is not unique any more. Panels allows setting CSS properties such as element class and ID, however, that only affects the wrapper of the form, but not the form ID itself. If I manually adjust the form IDs in the browser, AJAX works again, but then the forms don't sync any more, i.e. adjusting an option in one form is not reflected in the same secondary form.
Is there any possibility to have the best of both worlds, i.e. the ability to expose the form, place it multiple times on a page and have AJAX working?
Comment #84
i.bajrai commentedApplying this patch solved the issue for me.
http://cgit.drupalcode.org/views/commit/?id=96a54e0