I am using Drupal 8.4.4 and BEF 8.x-3.0-alpha3

I have created a block view and am using BEF to create a link filter based on a text list field

When I preview the view, the links work with AJAX. If I look at the href of one the the links, I see

http://joyer.localhost/admin/structure/views/view/portfolio/preview/block_1?_wrapper_format=drupal_ajax&field_type_value=SEO

If I place the block view on a page, the links no longer work with AJAX. Instead it requires a page reload. Looking at the href of one of the links, I see

http://joyer.localhost/test-page?field_type_value=SEO

It appears to be an issue only if I select links as when I change the views BEF filter to checkboxes instead of links, AJAX works on the page as expected.

No console errors appear.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

danjordan created an issue. See original summary.

dimashorokhov’s picture

Yes, I have this problem too. Can somebody help us? Please

danjordan’s picture

I noticed this issue for BEF Drupal 7 version. https://www.drupal.org/project/better_exposed_filters/issues/1268150

Looking at the final comment, there is a question on whether this fix got rolled into D8 version.

Does any have BEF Links working with AJAX on D8?

wolfhowling’s picture

I have the same problem, only happens with links.

danjordan’s picture

As a temporary workaround I am using checkboxes / radio buttons instead of links and using CSS to hide the buttons. Seems to be work OK. Only issue I can see so far I there is no css class to let you know which radio button is active.

wolfhowling’s picture

@danjordan you could use the :checked pseudo-class to add indicators to the label.

input:checked ~ label {
//style
}
lamp5’s picture

I confirmed the same problem on my site. I will try to fix this problem.

Peter van den Heuvel’s picture

Confirmed, same issue. Used checkboxes instead and styled them as links.

nimoatwoodway’s picture

Same Issue. Using D8.5.4 BEF 8.x-3.0-alpha4 with Cores Bartik Theme.

ocastle’s picture

Yes, i can confirm same issue. +1

alex.87’s picture

Same issue on Drupal core 8.5.6 & Better Exposed Filters 8.x-3.0-alpha4

Yoran Scholiers’s picture

I too have this issue. Core 8.6.1 and Better Exposed Filters 8.x-3.0-alpha4.

Renrhaf’s picture

Confirming this too

bfodeke’s picture

I am also seeing this same issue but it only shows up when logged in. Works with Ajax for anonymous users which is perplexing

paper boy’s picture

I have the same issue on Drupal 8.6.3 with BEF Alpha 5. Other than #14 I got it for visitors as well as logged in users.

demonde’s picture

I have the same problem. Ajax not working with BEF Nested Links. Is there any feedback by the maintainer.

paper boy’s picture

Haven't seen no feedback. But as #5 already mentioned, using checkboxes and styling them accordingly works like a charm. But still Ajax has to be enabled for that form.

.views-exposed-form .fieldset-wrapper .form-item input.form-radio {
    display: none;
}

Especially if you got multiple exposed filters for one form without Ajax enabled, the approach with the links won't work at all. Clicking a link would always navigate away from your page without taking into account selections in other exposed filters on that form.

demonde’s picture

Thanks @paper boy. This works, but it is too much of a workaround. I expect it to cause problems in a live enviroment.

It is unfortunate that there is no answer by the maintainer(s) after almost a year. Just to know what their review is even if it takes another year to fix this.

paper boy’s picture

Well, it's just some CSS styling and default forms behavior, what problems could that cause?

I've been using something similar on a D7 site for quite a few years without it causing any troubles.

ocastle’s picture

@demonde, Agreed bit of a work around, but styling checkboxes in this way is common in many scenarios.

I assume we just need to focus on porting the D7 patches into D8. How different is the code base between d7/d8 BEF?

Renrhaf’s picture

Same issue here !

ericdsd’s picture

I face the same issue with D8.7 BEF 8x-3.0-alpha6
view's ajax only works if i use radio/checkbox instead of links.

Note that with links it also breaks the ajax pager.

thejimbirch’s picture

Thanks to #5, #6, #17. Makes sense that the links wouldn't work with AJAX. Would also be a lot of links for crawlers to follow. I did the checkbox method and it works great. Here are the styles that I ended up going with in case anyone else could benefit from it.

/* Styling BEF Checkboxes to be like links so AJAX works. */
.views-exposed-form.bef-exposed-form input.form-radio {
  display: none;
}

/* Styling label like our links. */
.views-exposed-form.bef-exposed-form label {
  color: #083252;
  cursor: pointer;
  display: block;
  font-size: 16px;
  font-weight: normal;
  line-height: 1.63;
  padding: 1rem 0 0;
}

/* Which means we need to add a hover state. */
.views-exposed-form.bef-exposed-form label:hover {
  color: #0d5f9e;
}

/* Changes the label if the input is checked.  Like an active state. */
.views-exposed-form.bef-exposed-form input.form-radio:checked + label {
  color: #0d5f9e;
  font-weight: 600;
}

/* Throw a little arrow before the active label. */
.views-exposed-form.bef-exposed-form input.form-radio:checked + label:before {
  border-color: transparent transparent transparent #0d5f9e;
  border-style: solid;
  border-width: 4px 0 4px 8px;
  content: '';
  display: inline-block;
  height: 0;
  padding-right: 8px;
  width: 0;
}
truls1502’s picture

I can also confirm the issue.

berramou’s picture

I work with BEF with drupal 7 it works great.
But in D8 ajax not working with links.

imclean’s picture

berramou’s picture

Thanks @imclean for the update, i already saw the the related issue, for drupal 7, it works for me, but in drupal 8 the issue still.

imclean’s picture

Adding a related issue properly links the 2 issues. Anyone who comes to this issue can easily see the Drupal 7 issue and potentially have a go at porting the code over. Feel free to have a go if you like.

viswanathsai’s picture

Any Update or Patch on this issue ??

Etroid’s picture

Looks like someone could take a stab at porting the patch for D7 to D8. Active development is happening on the 8.x-4.x dev branch so please consider applying the patch there. Looks like the work will be two-fold:

- Add hidden select element to exposed form with all link values (used for store form submission values
- Attach javascript to page when bef_links are used.
- Prevents click on link element and select matching hidden value

D7 patch in question: https://www.drupal.org/files/issues/ajax_doesnt_work_with-1268150-132.patch

hockey2112’s picture

@thejimbirch, thanks for the CSS. I can't get the checked styling to work though... any tips? Can you maybe provide a link to the site where you used this CSS so I can take a look and attempt to troubleshoot/replicate on my website?

imre.horjan’s picture

Here's a patch.
In my solution URL is now generated quite similar as in the Views Infinite Scroll module (keeping only the query part of the URL, like "?field_type_value=SEO").
I also removed "_wrapper_format=drupal_ajax" form URLs, in order not to land on an AJAX result page.
This way BEF will work if used in a views block, and even if loaded by an AJAX request (for example you already used an AJAX pager).

Let me mention that my solution doesn't actually use AJAX for reloading the view. A full page reload is done.
I appreciate if you can review and test it.

imre.horjan’s picture

Status: Active » Needs review
dshields’s picture

Status: Needs review » Needs work

Not to be rude, but because the "solution doesn't actually use AJAX for reloading the view. A full page reload is done,", I'm setting this back to "Needs work".

Piratawww’s picture

I still have the same problem with the last dev release. #32 dont help with ajax link problems

imre.horjan’s picture

Hiding my patch...
As I remember we changed links to checkboxes and it works.

Oleksiy’s picture

playful’s picture

This continues to be an issue in BEF 8.x-4.0-beta1. Using Drupal 8.8.6. Worked fine in Drupal 7... any update on this?

Nigel Cunningham’s picture

In my case, I've found that the issue is simply that I'm using Select 2 as well, and the auto submission works if I add a little delay for Select2 to update the selection before it clicks the button for me. Attaching a patch that does this.

Nigel Cunningham’s picture

Status: Needs work » Needs review
Neslee Canil Pinto’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Patch no longer applies

KapilV’s picture

Assigned: Unassigned » KapilV
KapilV’s picture

Assigned: KapilV » Unassigned
Neslee Canil Pinto’s picture

@kapilkumar0324 why did you assigned and then unassigned yourself?

Does that mean you are creating a patch for this issue?

anushrikumari’s picture

Assigned: Unassigned » anushrikumari
anushrikumari’s picture

Assigned: anushrikumari » Unassigned
Status: Needs work » Needs review
FileSize
740 bytes

Sorry, Ignore this patch as I uploaded the wrong one.

Radelson made their first commit to this issue’s fork.

Radelson’s picture

Version: 8.x-3.x-dev » 8.x-5.x-dev
Status: Needs review » Needs work
adityasingh’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
627 bytes

Reroll the patch for 8.x-5.x. Please review.

Status: Needs review » Needs work

The last submitted patch, 49: better_exposed_filters_2938761-49.patch, failed testing. View results

Radelson’s picture

I've created a merge request following #30 recommendations.

I don't think #49 and #39 are addressing the problem described in the issue summary.

The merge request is trying to fix the original issue : the Links plugin triggers a full page reload even though the views is configured to use AJAX.

Maybe another issue should be created to address #39. It seems related to the auto submit behavior when using Select2 but not related to AJAX using links.

gulshk’s picture

When are you going to merge?

Tom Grootjans’s picture

I've created a patch for the changes made in the merge request mentioned in #52

Radelson’s picture

Status: Needs work » Needs review

Setting as needs review, it seems to work well enough for us and it's in use elsewhere.

igonzalez’s picture

#54 works for me

monya’s picture

Here's a small fix for the case with two or more bef links on the page.

Volker23’s picture

testing #54 and #57 neither patch works for me. Drupal 9.1.4 BEF 8.x-5.0-beta1

camslice’s picture

I'm getting the same testing patches #54 and #57. Neither seem to work on Drupal 9.1.5 BEF 8.x-5.0-beta1

Radelson’s picture

Status: Needs review » Needs work

Setting this as needs work as it doesn't seem to work for some people.
The patch is still in use for us but we will maybe run into problems when we update to 9.x.

mudassar774’s picture

It don't works with d9

savage1974’s picture

FileSize
289.59 KB

It works with drupal 9.18. but with some nuances (view - page's display) - see attached pic.

cedewey’s picture

Patch #57 works for me on Drupal 8.9.16

nortmas’s picture

Good job guys! But I guess there is still a small issue. After I clicked a link, I can't unclick it to reset the results, which is a problem from my point of view.

nortmas’s picture

Here is the patch, which fixes the issue mentioned in comment #64

Fabsgugu’s picture

Patch #65 works for me on Drupal 9.1.10

Hydra’s picture

Just tested this patch while researching - the patch works, but only for one exposed filter using links option at once. It will break when using multiple filters at once.
Another option would be to go with the radio/checkbox solution build in and use heavy css to make them look like links.

camslice’s picture

Unfortunately patch #65 doesn't work for me. Page reloads every time.

cedewey’s picture

The page is still refreshing for me as well when a link filter is clicked on a Views block using AJAX.

fskreuz’s picture

The patch from #65 somewhat works with a few caveats:

- What the patch does is hide the select and add another form element for the links. This causes administration to be weird because you're really still administering the select, not the set of links. The links appear at the end of the filters. This also makes filter order and modules like VEFL go weird.
- The patch doesn't work when you pull out the exposed form as a block, page will still refresh. That's because viewExecutable->preExecute() is never called to update the view's AJAX capabilities from the display handler. Meaning viewExecutable->ajaxEnabled() will always return false. This check should instead be if($this->view->display_handler->ajaxEnabled()) to grab the AJAX capability directly from the associated display.

Tried a few things but didn't work out. Sticking with the "hide the checkboxes and style labels as buttons" approach for now.

joseph.olstad’s picture

cedewey’s picture

I tested https://www.drupal.org/project/better_exposed_filters/issues/3232628 and it did not resolve the filter link behavior for me. In my case the site is on Drupal 8.9.19

Krzysztof Domański’s picture

Deactivate the current link.

rokzabukovec’s picture

Status: Needs work » Needs review
FileSize
1.22 KB

I used this patch to getting the exposed filters in view blocks work. Please review.

cedewey’s picture

@Krzysztof Domański your patch worked for my use case. Thank you!

furamag’s picture

Patch #73 works for me. Thank you!

ysamoylenko’s picture

Hello everyone.
I've tested patch #73 and it works fine with one additional fix mentioned by @fskreuz in #70.

I've added an additional check for display handler ajax status if default view ajax status could not be resolved.

For my particular case, it works.

Please review the patch and interdiff.

ysamoylenko’s picture

FileSize
5.22 KB
1.05 KB

Please ignore #79 and use #80 as I accidentally removed JS fixes from #73 in #79.
Sorry for that.
Please review #80 instead.

ipinchuk’s picture

Status: Needs review » Reviewed & tested by the community

Hi there,

Patch #80 has been checked. It works fine.

Thanks for your contribution

ocastle’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
5.37 KB
677 bytes

I've just tried this patch on a new project.

There is an issue when the exposed form is used in a block.
Due to the change in the html structure the form submit isn't submitted.

$wrapper.closest('form').find('.form-submit').click();

Closest form isn't found as the wrapper element surrounds the form element rather than the form containing the wrapper.

Attaching patch to solve this.

druplr’s picture

This patch adds support for multiple BEF links fields. For an example, you can try the test view attached below, place the exposed filter block, and add some test content (published/unpublished, sticky/unsticky, promoted/unpromoted).

Also, instead of deactivating the currently selected BEF link, the new patch follows the original behaviour of the module: re-selecting the selected BEF link, deselects it now.

druplr’s picture

My previous patch (#83) when combined with "#2901927: Preserve links filter value when submitting Views exposed form" and AJAX enabled results in two form elements for every BEF link filter:

  • the original <select>
  • the hidden input with its name ending in "_bef_links"

As a result, the query string becomes unnecessarily long.

So I tried to include the patch from "#2901927: Preserve links filter value when submitting Views exposed form" to patch #83. After some adjustments, the new patch turned out to be leaner and simpler.

This new patch supports:

  • multiple BEF links filters
  • original behaviour of the module (re-selecting the selected BEF link, deselects it.)
  • AJAX enabled
  • AJAX disabled
druplr’s picture

leanderjcc’s picture

Status: Needs review » Reviewed & tested by the community

Hi,

the patch at #84 fixed the issue for me with version 5.0.0. Very nice work! Test returned green so marking this RTBC.

whitewebs’s picture

Hello!

I experienced this issue on one of our sites and it was tricky to spot what was at fault. Great to see this has been flagged as an issue and has been worked on. I have reviewed the patch at #84 and can confirm it works nicely!

Thank you kindly.

Simon

  • rlhawk committed 4447866 on 8.x-5.x authored by druplr
    Issue #2938761 by druplr, ysamoylenko, Radelson, ocastle, Krzysztof...
rlhawk’s picture

Status: Reviewed & tested by the community » Fixed

This looks good and is committed. Thanks to all who contributed to the solution.

Neslee Canil Pinto’s picture

We also need to apply, test, and commit these changes for 8.x-4.x branch.

Neslee Canil Pinto’s picture

Added the changes to 8.x-4.x branch, made manual reroll for the branch.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.