Autocomplete filter ignores full dataset when contextual filters are present

Created on 4 April 2025, 2 months ago

Problem/Motivation

The Views Autocomplete Filters module currently forces contextual filters to be applied during autocomplete searches, preventing users from searching across the entire dataset. This limitation occurs because the module doesn't properly handle cases where we want to temporarily ignore contextual filters during autocomplete operations.

<!--break-->

The current implementation modifies the argument configuration:

    $enable_arguments = $expose_options['autocomplete_contextual'] ?? FALSE;
    // Force "Display all values" for arguments set and ignore "No Contextual
    // filter present" settings unless indicated by 'autocomplete_contextual'.
    $arguments = $display_handler->getOption('arguments');
    if (!empty($arguments) && !$enable_arguments) {
      foreach ($arguments as $k => $argument) {
        $arguments[$k]['default_action'] = 'ignore';
      }
      $display_handler->setOption('arguments', $arguments);
    }

This approach is problematic because it alters the wrong display handler's configuration. Like it says: When the filter value is NOT in the URL If I don't misunderstand something, this logic should operate when the filter value IS in the url.

Steps to reproduce

  1. Enable the default Glossary view
  2. Try using autocomplete on a filter
  3. Observe that the autocomplete results are restricted to entries matching the current letter's filter
  4. Expected: Autocomplete should search across all entries regardless of the current contextual filter

Current Behavior: Autocomplete searches are restricted to the current contextual filter's subset of results, limiting the user's ability to find matching entries across the entire dataset.

Expected Behavior: Autocomplete should be able to search across the entire dataset when needed, regardless of active contextual filters.

Proposed resolution

Instead of modifying the display handler's configuration, we should set the contextual filter value directly the the Exception's wildcard value.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇭🇺Hungary szantog

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @szantog
  • Merge request !31#3517315: Fix contextual filter handling → (Open) created by szantog
  • Pipeline finished with Failed
    2 months ago
    Total: 204s
    #465079
  • 🇷🇴Romania vasike Ramnicu Valcea

    @szantog thanks for the issue and the proposal MR

    I'm not sure about this issue is really a bug.
    So first thing: did you try your View(s) with autocomplete_contextual (Allow Contextual filters to apply to this filter label) option selected for your Autocomplete filters?
    This option is disabled by the default, as it was introduced at the later stage, when this kind of issues needed to be covered.

    If this "hint" still do not solve this issue case, this mean we need a new feature to cover ...

    For now i'll change the issue type and status ... to get the "new results" first.

    Second: this module has tests (Gitlab CI/CD pipeline) for while, so this means whatever MR is proposed, it needs to be Green all Gitlab CI/CD pipelines should pass - before "Needs review" status.
    Other wise, it means the solution/isssue "Needs work".

  • 🇭🇺Hungary szantog

    So first thing: did you try your View(s) with autocomplete_contextual (Allow Contextual filters to apply to this filter label) option selected for your Autocomplete filters?

    Yep, this was the first setting I played with. "Allow Contextual filters to apply to this filter" - doesn't this mean if I checked this, then the contextual filter will be applied, so the autocomplete result should be limited by the filter? In the particular glossary view the 'TRUE' value of this setting means that I'd like to search with the current letter's result.

    If it is not checked, that means I want to search in every letters, am I right?

    Did you try the core's glossary view? This the perfect example to present this logic.

    If we have a deal, I'll take care of the tests. :)

Production build 0.71.5 2024