When using an exposed filter to search for something that yields no results, the view completely disappears. The expected behavior is that the exposed filters, reset button, and no results text should appear.

When I try debugging by placing a breakpoint inside template_preprocess_views_view(), xdebug catches when the results are shown (no query string added to the url), but if a filter is added that returns no records, the breakpoint doesn't catch.

These patches fix the issue for D7 but can no longer be applied in D8: https://www.drupal.org/project/viewfield/issues/477244

Are other folks experiencing this as well, or am I missing something in my setup? Thanks!

Comments

jimafisk created an issue. See original summary.

jerdavis’s picture

You have a no-results set?

jimafisk’s picture

Thanks for the quick response @jerdavis! Yes, I have a simple "Global: Text area" no results behavior on the view. I take it you can't reproduce the bug on your end?

jerdavis’s picture

I probably can. I'll set up another test and verify and double check 7.x as well.

jerdavis’s picture

I'm seeing my global no-result here. Did you download the latest dev snapshot or release from yesterday and try that?

jimafisk’s picture

I just ran lando composer require drupal/viewfield:3.x-dev. Then removed my contrib modules and ran lando composer install which seems to put me at commit aef60a6, but I'm seeing the same thing. I must have an error in one of my templates. I'll do a little more digging and close the loop here when I find something.

jimafisk’s picture

Oh also, I forgot to mention that the viewfield is on a paragraph that is being placed on the node. That might be an important detail.

jimafisk’s picture

Another nonstandard thing I'm doing is setting the form action value for the exposed filters. Basically when using an exposed filter it was sending me to the path specified in the page display for the view, however I wanted to stay on the current node where the paragraph (with the viewfield) was placed. I accomplished that like this:

/**
 * Implements hook_form_alter().
 */
function mymodule_form_alter(&$form, $form_state, $form_id) {
  if ($form["#form_id"] == 'views_exposed_form') {
    $current_path = \Drupal::service('path.current')->getPath();
    $form["#action"] = $current_path;
  }
}

The no results behavior does indeed work if I comment that out and allow the exposed filters to send me to the path specified in views. Is there a better way to accomplish the behavior of staying on the node where the paragraph (containing the viewfield) is placed? Would using a block display instead of a page display work by default? This is for a migration project, so I was simply trying to recreate what previously existed in D7, which was using page displays. Thanks!

jerdavis’s picture

Is AJAX turned on in your view? If so you shouldn't need the form_alter() and it may improve behavior.

jerdavis’s picture

Is the exposed form part of the view or are you using it from a separate block?

jimafisk’s picture

AJAX was turned off, enabling it throws a TypeError: offset is undefined error in the console and doesn't narrow results.

The exposed filters are part of the view itself, not a separate block.

jerdavis’s picture

Any further information on the error? Is that resulting from your custom code? Or being thrown with regard to Viewfield?

jimafisk’s picture

I believe it's error with enabling AJAX, more specifically ajax_view.js. It doesn't happen when setting "Use AJAX" to "no" in the view settings. I pasted the full browser console errors below.

Chrome:

ajax_view.js?v=8.6.17:125 Uncaught TypeError: Cannot read property 'top' of undefined
    at Drupal.AjaxCommands.viewsScrollTop (ajax_view.js?v=8.6.17:125)
    at ajax.js?v=8.6.17:435
    at Array.forEach (<anonymous>)
    at Drupal.Ajax.success (ajax.js?v=8.6.17:433)
    at Object.success (ajax.js?v=8.6.17:234)
    at Object.t.success (jquery.form.js:278)
    at i (jquery.min.js?v=3.2.1:2)
    at Object.fireWith [as resolveWith] (jquery.min.js?v=3.2.1:2)
    at A (jquery.min.js?v=3.2.1:4)
    at XMLHttpRequest.<anonymous> (jquery.min.js?v=3.2.1:4)

Firefox:

TypeError: offset is undefinedajax_view.js:125:9
    viewsScrollTop ajax_view.js:125
    success ajax.js:435
    forEach self-hosted:266
    success ajax.js:433
    success ajax.js:234
    jQuery 5
    success
        i
        fireWith
        A
        c
jerdavis’s picture

Have you or the theme you're using overridden Views templates? https://www.drupal.org/project/drupal/issues/2797587#comment-12450024

jimafisk’s picture

Good call, yes we did override the views-view.html.twig template. I still couldn't get the {{ attributes }} working properly though - possibly something we're messing up in preprocess with custom code.

I tried using a block display instead of a page display on the view, but then the exposed filters no longer appeared so I switched back to a page display.

Solution: Finally I noticed that I had not configured the viewfield's display settings correctly on the paragraph. So under "Manage Display" if you click the gear icon to the right of your field, just tick the "Always build output" checkbox, update and save. Hopefully that helps someone!

Thanks for all the help debugging @jerdavis! This is all set for us :)

jimafisk’s picture

Status: Active » Fixed
jerdavis’s picture

Status: Fixed » Closed (fixed)

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