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.
Problem
Filter groups adding and removing does not work at all.
The involved files are:
- core/modules/views_ui/js/views-admin.js
- core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/RearrangeFilter.php
Steps to reproduce
- Edit a View
- Add at least one Filter
- Click on "And/Or Rearrange" in the Filter options dropdown
- Click on "Create new filter group"
- Nothing happens
Beta phase evaluation
Issue category | Bug because adding and removing filter groups is broken |
---|---|
Issue priority | Major because it is a UX issue of a feature which doesn't work. |
Prioritized changes | The main goal of this issue is usability |
Comment | File | Size | Author |
---|---|---|---|
#89 | not-hidden.png | 87.58 KB | marthinal |
#89 | hidden.png | 80.48 KB | marthinal |
#85 | interdiff-2168893-83-85.txt | 2.51 KB | marthinal |
#85 | 2168893-85.patch | 5.32 KB | marthinal |
#83 | 2168893-82.patch | 6.32 KB | marthinal |
Comments
Comment #1
star-szrConfirmed.
Comment #2
euphoric_mv CreditAttribution: euphoric_mv commentedComment #3
dawehnerThank you for reporting the issue. I consider this as a major bug, at least.
Also updating some tags.
Comment #4
nod_Comment #5
dawehnerThere are several bugs:
* The actual add functionality does not work (even if you show the button itself)
* The button is hidden from the no-JS variant
Given that the functionality is pretty useless so this is a huge regression compared to d7.
Comment #6
euphoric_mv CreditAttribution: euphoric_mv commentedThere are bugs in the javascript and php files too.
I found it in javascript and i will post a patch file today, but in php file, concrete in core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/RearrangeFilter.php, we can't use logic like in Drupal 7.
For example, there is no $form_state['clicked_button'] element and there are more bugs.
Comment #7
catchIt's useless but it's a self-contained bug in the views UI, so major.
Comment #8
euphoric_mv CreditAttribution: euphoric_mv commentedIn this patch I fixed javascript bug for click on "Create new filter group" link.
It work now but there is a problem because it doesn't trigger ajax. It opens new page with JSON output and when I go back and click again on rearrange the filters, new filter group is shown. I can't figure out why this happens.
Please test it and if someone has idea how to solve the problem, that would be great.
Comment #9
euphoric_mv CreditAttribution: euphoric_mv commentedComment #10
nod_The JS error is because event is not a defined variable in that scope. function definition needs to be changed to
clickAddGroupButton: function (event) {
no need forreturn false;
.I don't know why the ajax stuff doesn't trigger though.
Comment #11
nod_The input clicked is not ajax enabled so it wouldn't do anything.
Still doesn't work but at least no JS error.
Comment #12
euphoric_mv CreditAttribution: euphoric_mv commentedthis.addGroupButton.trigger('mousedown').trigger('submit');
doesn't work. I puttedthis.addGroupButton.click();
and thenevent.preventDefault();
and then it fire button.Also, by adding class 'use-ajax', button for add group get class 'ajax-processed' but on submit it still open page with JSON ouput.
I noticed that other buttons on view has class 'drupal-ajax-processed'.
Comment #13
marthinal CreditAttribution: marthinal commentedAbout the json output we have the same behavior for d7 using .click(). If we add the #ajax attribute with a 'path' for example, we obtain the class 'drupal-ajax-processed' added to the input. Also the form submit is executed as expected but for the moment this is where I am. Maybe this info is helpful .
Comment #14
euphoric_mv CreditAttribution: euphoric_mv commented@marthinal Your post was very helpful. Thank you.
I needed to change some other lines in PHP too, like
$form_state['view']->addFormToStack('rearrange-filter', $form_state['display_id']);
and it wirks for me now.Same problem appears with removing filter groups.
Comment #15
dawehnerWOW, we need javascript tests!
It is certainly wrong to still rely on current_path(), isn't there something on the request object which does the same?
Comment #16
euphoric_mv CreditAttribution: euphoric_mv commentedComment #17
euphoric_mv CreditAttribution: euphoric_mv commentedI tried to find path on the request object but no results.
Comment #18
euphoric_mv CreditAttribution: euphoric_mv commentedComment #21
euphoric_mv CreditAttribution: euphoric_mv commentedSo, we need to replace current_path in whole views system, right?
Comment #22
euphoric_mv CreditAttribution: euphoric_mv commentedI don't know is this right solution but i am getting path that I need. Please advice.
Comment #23
blueminds CreditAttribution: blueminds commentedRerolled and reviewed. JS file is fixed in HEAD now. Looks fine, only not sure why we need to remove "filter" from
Other than that I think RTBC.
Comment #24
Elijah Lynn@#23
The 'filter' appears to be for a mandatory parameter of $type.
public ViewUI::addFormToStack($key, $display_id, $type, $id = NULL, $top = FALSE, $rebuild_keys = FALSE)
https://api.drupal.org/api/drupal/core%21modules%21views_ui%21src%21View...
Comment #25
Elijah Lynn@#23
I am seeing these console errors when clicking the "Create new filter group" and nothing happens.
Comment #26
Elijah LynnComment #27
Elijah LynnMy actual path is http://sandbox/d8/admin and not http://sandbox/d8/d8/admin like it is searching for, and there are multiple paths of http://sandbox/d8/d8 in the network tab. I don't have time to debug this just yet but I think this is the main issue in my case of having Drupal installed in a subdirectory.
Comment #28
Elijah LynnHere is a patch that uses getPathInfo() instead of getRequestUri and removes the subdirectory from the URL. It also adds 'filter' back.
Now on first click it does add a new filter group but on subsequent clicks it throws an error.
Comment #30
Elijah LynnOkay, some work that still needs to be done.
POST http://sandbox/d8/admin/structure/views/ajax/rearrange-filter/345/default/filter 404 (Not Found)
Comment #31
lauriiiRerolled the patch
Comment #32
lauriiiComment #33
joelpittetAssigning to @nod_ because maybe he can clear up why the JS isn't doing the ajax requests correctly and closing the window once called or maybe point us in the right direction here.
Selfishly this is holding up our twig conversions but also it's quite a big bug for beta as well.
#1963978: Convert theme_views_ui_build_group_filter_form() to Twig
Comment #34
lauriiiComment #35
nod_Looked into it it's out of my hands. The no-js version of adding a group doesn't work at all.
From what I understand the group configuration form doesn't get added to "the stack". It also means that when using JS there will be a CloseDialogCommand added to the ajax commands to close everything and start fresh. The JS bug is a side effect of a PHP problem I don't know how to fix.
Comment #36
marthinal CreditAttribution: marthinal commentedI was reviewing this patch with @dawhener and found the problem.
Comment #37
tim.plunkettWe don't use this anywhere
This line doesn't make sense to me. First, why call it twice? Second, why use the result only if it casts to FALSE? Thirdly, current_path() isn't even a function any more.
Comment #38
jhedstromThis still doesn't seem to work quite right in manual testing. After adding a filter group, I can drag items in, but the group is not saved.
Comment #39
marthinal CreditAttribution: marthinal commented@tim.plunkett Done.
@jhedstrom I think you need to drag more to the bottom. I was testing and it works... weird.
thanks!
Comment #40
jhedstromConfirmed that dragging more than one filter all the way to the bottom will allow the group to be saved, but surely there are use-cases for only adding one filter to a new group (eg, a single filter belonging to a group joined by OR).
Also, after the group is created, there's an escaping issue on the main form:
Comment #42
jhedstromActually, adding a single filter works if it is dragged all the way to the bottom. I interpreted #39 as meaning more than one :)
Comment #44
tim.plunkett$this->getRequest()->getRequestUri(), I guess
Comment #45
marthinal CreditAttribution: marthinal commented@tim.plunkett Yes thanks
Added related bug about double-escaped filters.
Comment #46
Anonymous (not verified) CreditAttribution: Anonymous at Druid commentedThe remove group button still doesnt work, altough the group is removed if its left empty but its bit confusing to have a button that does nothing.
So should we remove the button, or make the button work?
Comment #47
marthinal CreditAttribution: marthinal commentedRemoved duplicated code, fixed Create new group and remove group + avoid duplicate select for the operator.
Thanks to nod_ for the help with the js for the select for the operator :)
Comment #48
nod_This works for me, I'll let tim or someone else confirm it.
Comment #53
marthinal CreditAttribution: marthinal commentedComment #54
dawehnerI'm a bit confused as the inline template changes are missing?
Comment #55
marthinal CreditAttribution: marthinal commentedThis part is fixed here #2469563: Double-escape on Views filters
Comment #56
jhodgdonBoth nod_ and marthinal have been testing this manually in Views. I also just ran it on simplytest.me, and it fixes the bug described in the issue summary: you can now add/remove groups in the Filter rearrange dialog.
I took a look at the code. The changes are straightforward and the code looks clean to me.
No tests because it's a JS bug. Sigh.
Anyway, let's get this bug fix in!
Quick beta eval: This fixes a Major UI Bug, and there are no API changes or disruption.
Comment #58
nod_#2461531: ESlint 0.18.0 compatibility and new rule
Comment #59
lauriiiComment #60
JeroenT@lauriii,
I think this is the wrong patch.
Comment #62
lauriiiThis should be the right one :) Sorry for the previous one!
Comment #63
joelpittetBack to RTBC
Comment #64
dawehnerI'm curious whether we can write a test for at least the second half of the problem (the part in PHP).
Comment #65
webchickGood question.
Comment #66
joelpittet@marthinal and @nod_, thoughts on possible tests for mostly #47?
Comment #67
marthinal CreditAttribution: marthinal commentedWe can create a group filter and then remove it. We don't need js enabled for it, so maybe this is enough to cover this part...
I can work on it.
Comment #68
marthinal CreditAttribution: marthinal commentedI'm using the test I have created at #2469563: Double-escape on Views filters.
Comment #70
joelpittet@marthinal that is awesome, thanks for separating out the test and pass patches.
There are some coding standards nitpicks and one not so nit pick outside the test, would you mind tackling them? I'd RTBC this again after these are tackled.
Also thanks for moving that todo move one too!
Can we avoid this overly specific selector? I had this as a pet peeve in D7 because I couldn't covert theme_button to a button element because these things in panels and views.
Nit: Short array syntax :s/array()/[]/ and can be one line.
Ditto
Nit: Extra line break.
Nit: Short array syntax s/array()/[]/
Nit: here too [].
Nit: Wrap on 80 chars.
Nit: Short array syntax s/array()/[]/
Nit: Short array syntax s/array()/[]/ and can be one line.
Nit: Short array syntax s/array()/[]/
Nit: Extra line break.
Any changed/new diff hunks can get the short array syntax(don't go out of the hunks or it could cause needless rerolls on other patches and make the committers and reviews cross:P)
Comment #71
marthinal CreditAttribution: marthinal commented@joelpittet sure! and thanks for reviewing.:)
1. trigger('mousedown') is needed otherwise it does not work.
Here the same situation:
The rest are fixed as well.
Comment #73
joelpittetOh I wasn't complaining about the mousedown. I'm sure that was needed however weird that looks. I was just mentioning the need for 'input' in the CSS selector.
It makes it hard to theme buttons by hardcoding what element that class is on.
Also missing a few ending commas, I'll identify them when I get into the office on dreditor.
Comment #74
joelpittetSo %s/input#'/#'/
Would love the same thing here but I don't know where views-group-title is used so we can leave the tr. on here.
Needs a comma at the end, and can make that one line.
Same here, one line and comma at the end.
One line, OR at least if not needs a comma after TRUE.
Comment #75
marthinal CreditAttribution: marthinal commented1. Done. ( Sorry added while working on it :) )
2. Without removing tr for the moment.
3. Done.
4. Done.
5. Done
Thanks!
Comment #76
joelpittetAwesome thank you @marthinal
Comment #77
olli CreditAttribution: olli commentedI'm still seeing #38 with this patch. Do we have an issue to fix it?
We use 'url' now so these lines are same as
'#ajax' => ['url' => NULL],
, right? The 'use-ajax-submit' class with trigger('click') could also work here.Comment #78
joelpittetI'm not sure the answer to that @olli, so I'm needs reviewing this to see if someone knows?
Comment #81
marthinal CreditAttribution: marthinal commentedFor the moment rerolled... Not sure if we should use url instead of path. So needs review and this is a quick change anyways...
Comment #83
marthinal CreditAttribution: marthinal commentedI can see info about it and I think that using url we avoid to call getRequest() method.
Comment #84
YesCT CreditAttribution: YesCT commentedThanks for #83. Seems to make sense about url.
in #70 @joelpittet said
we do not need to change this for the patch to work.
same.
same.
nit, comment indent is off.
Comment #85
marthinal CreditAttribution: marthinal commentedDone!
Thanks! :)
Comment #86
joelpittet@marthinal thank you for the remaining cleanup!
Comment #87
alexpottThere's no confirmation that #38 is solved or is a followup.
Comment #88
joelpittet@alexpott, you're right it does work but there just seems to be a bug left with two drop areas, not sure if that is a template level thing or just JS duplicating dom elements... so yes this does still needs work.
Will tag this as novice for someone with javascript skills can look at why this is the case.
When you create a new group there are two drop cells and the second one is where the filter needs to be dropped into that second group.
Comment #89
marthinal CreditAttribution: marthinal commented@joelpittet I think this is because the description is hidden. And not sure if it should be hidden...
Hidden:
Not hidden:
Comment #90
joelpittetInteresting @marthinal could you post a patch with it unhidden? We can test it further. I don't know if it's supposed to be hidden and why that would effect the drop areas. Maybe a class name collision or something.
Comment #91
marthinal CreditAttribution: marthinal commented@joelpittet Before adding it to the patch I prefer to know if we want to hide it.
views-admin.js
I was discussing with @lauriii about it and maybe we should open a new issue about this problem and fix this one.
Comment #92
marthinal CreditAttribution: marthinal commented@joelpittet Before adding it to the patch I prefer to know if we want to hide it.
views-admin.js
I was discussing with @lauriii about it and maybe we should open a new issue about this problem and fix this one.
Comment #94
lauriiiI created a follow up for broken dragging thing. I don't see how it would fit she scope of this issue. #2493945: Views filters dragging in the grouping view is broken
Comment #95
joelpittet@marthinal Since you mentioned that unhiding it fixed the drag drop groups I was hoping you'd post a patch so we could review your findings. But yes this patch as it is now makes things kinda work more than it does so moving it to a follow-up seems reasonable considering the amount of time it took to get this far.
Comment #96
lauriiiThere is already solution suggested on the other issue and it relates to problem in the tabledrag - so no need to worry about that here :)
Comment #97
alexpottOkay lets fix the tabledrag in the other issue.
This issue addresses a major bug and is allowed per https://www.drupal.org/core/beta-changes. Committed d982616 and pushed to 8.0.x. Thanks!
Comment #100
rahim123 CreditAttribution: rahim123 commentedThis is also broken in the current release of Drupal 7, as described in the original bug report.
Comment #101
rahim123 CreditAttribution: rahim123 commentedComment #102
joelpittetComment #103
rahim123 CreditAttribution: rahim123 commentedLooks like this is actually a conflict with the hide_submit module:
https://www.drupal.org/node/1939426
Comment #104
rahim123 CreditAttribution: rahim123 commentedComment #105
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedThe original bug report was always about Drupal 8 (the early comments in this issue refer to it as a regression compared to Drupal 7).
Also, Views is not in Drupal 7 core.
I think you're probably right that the problem you're experiencing is covered by the issue you linked to. (In my experience, filter groups do work fine in Views for Drupal 7 in the general case.)
Comment #106
certifiedGeek CreditAttribution: certifiedGeek as a volunteer commentedI'm creating a site in Drupal 8.1.8 and the filter grouping is not working for me. I can create the filter group and add items to it but it does not save. Is this broken again, or are there other modules that cause this to break?
Comment #107
joelpittet@certifiedgeek you may have a new issue. First search open issues and if not found, open a new one and post a link here to that issue
Comment #108
nod_#2493945: Views filters dragging in the grouping view is broken
Comment #109
thtas CreditAttribution: thtas commented@certifiedgeek
Same here with 8.1.10, but i have a lot of custom code and contrib modules (in various un-stable states) which could be causing it.
No errors in the JS console or watchdog to indicate a problem.
Comment #110
egouleau CreditAttribution: egouleau commentedsame here :( totally broken even after update to 8.2 ...
Comment #111
TomSaw CreditAttribution: TomSaw commentedSame for me running Drupal 8.2.3
Comment #112
anouSame problem has comment #106 on drupal 8.2.3:
I can create new group, add field to it but after applying my changes, nothing is saved. Coming back to it, I find only one group...
Comment #113
typotraum CreditAttribution: typotraum commentedSame for me -> filter groups are gone
Comment #114
handkerchiefSame for me --> #112
But with drupal 8.2.4 :(
Comment #115
handkerchiefDoes anyone reopen this issue or do we have to create a new issue? I'm not waiting as long as my comment predecessors :)
Comment #116
joelpittetThere are a couple of issues that relate to this already in the queue, but if you don't see it in this list please create a new one.
#2215857: Behaviors get attached to removed forms
#1939426: I cannot Create new filter group
#2244489: Required exposed grouped filter remembers values when they should not
#2233695: optional exposed grouped filters on a View that requires exposed filters save their default values as remembered values when they shouldn't
Or any of these:
https://www.drupal.org/project/issues/drupal?text=exposed+grouped+filter...
Comment #117
arnaud-brugnon CreditAttribution: arnaud-brugnon commentedI have the same issue.
That seems to be bound to drag and drop.
If you disabled it (Show row weights), you will be able to do everything you want to.
Comment #118
Rob230 CreditAttribution: Rob230 commentedIn Drupal 8.3.2 it also doesn't save when I add groups or rearrange filters.
Edit: I found a workaround. Click 'show row weights' and instead of dragging, just choose the group with a drop down. It seems to work then.
Comment #119
sureshcj CreditAttribution: sureshcj commentedHi All,
In Drupal 8.4.2, It also has same issue. Also, I have faced another issue like condition not working as expected.
Kindly find the test case.
I have to filter the node which is linked with term 1 or term 2, To archive this, I have created the view with filter condition like below.
Filter criteriaFilter criteria
Content: Published (= Yes)
AND
Content: filed 1(= term 1)
OR
Content: filed 2 (= term 2)
The output sql query like below:
WHERE (((node__field_1.field_1_target_id = '12')) AND ((node__field_field_2.field__field_2_target_id = '39'))) AND (node_field_data.status = '1')
Kindly anyone gives me the suggestion to archive the same.
Thanks in advance.
Comment #120
michaelfavia CreditAttribution: michaelfavia commentedHere to confirm that the workaround in #118 works for now.
Comment #121
liquidcms CreditAttribution: liquidcms commentedwhy is this marked as fixed?
I have 8.4.3 and filter groups have 2 issues:
- the UI is messed up, can't drag a filter to a new group when first created - but, it looks like it works after rearrange is first saved
- the resulting sql is wrong (OR is not ORing)
perhaps this is fixed in newer version but i think 8.4 is current version.
http://take.ms/JWQfM
Comment #122
azovsky CreditAttribution: azovsky commentedIt is NOT fixed on D.8.4.5.
Comment #123
inversed CreditAttribution: inversed commentedNot to bump an old post but the workaround for fixing the broken sql "(OR is not ORing)" appears to be choosing the "Reduce duplicates" option for each of the filters in the OR group.
Comment #124
tedwyer CreditAttribution: tedwyer commented@inversed. Where is the "Reduce duplicates" option? Never seen this. Are you referring to Distinct? Thanks.
This is still broken in 8.5.6. This has been an issue for years. It's enough to challenge one's faith in Drupal 8.
Comment #125
Mikechr CreditAttribution: Mikechr at Tabs & Spaces commentedCan confirm, as @tedwyer said this is still broken in 8.5.6
Comment #126
imclean CreditAttribution: imclean commentedIt is also broken in 8.6.0 when trying to drag & drop. You can still create the groups using row weights instead. See #2838909: New filter groups are not saved, specifically #7.
Comment #127
dlaufer CreditAttribution: dlaufer commentedI'll confirm that the workaround in #118 (using `show row heights` instead) works and that the UI is still broken.