Add option to remove (instead of hide) unnecessary filters

Created on 27 February 2025, 2 months ago

Problem/Motivation

I would like the option to actually remove unnecessary filters from a configurable views filter block, rather than just visually hide them.

The current strategy of visually-hiding the unnecessary filters results in two problems on my site:

- Lots of unnecessary markup on the page
- Current values/selections from all of the visually-hidden filters are still included in the views exposed form submission request (this can be desirable or problematic depending on your goals - problematic in my case)

Actually removing the unnecessary filters resolves both of these problems.

Steps to reproduce

1. Set up a configurable views filter block, leaving some filters unchecked
2. Load a page with the block and see that the filters are still present in the block's form, just visually-hidden

Proposed resolution

Add a new "Filter removal strategy" select element into the block's configuration with options:
- Visually hide
- Remove

"Visually hide" would be the default, but choosing "Remove" would actually remove unnecessary filters from the block's form.

Remaining tasks

MR + review.

User interface changes

New configuration choice in block settings.

API changes

None.

Data model changes

None.

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States chrisolof

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

Merge Requests

Comments & Activities

  • Issue created by @chrisolof
  • πŸ‡ΊπŸ‡ΈUnited States chrisolof

    chrisolof β†’ changed the visibility of the branch 3509467-add-option-to to hidden.

  • Pipeline finished with Failed
    2 months ago
    Total: 131s
    #436164
  • πŸ‡¨πŸ‡ΏCzech Republic rob.sipek@gmail.com

    Hi Chris, I really appreciate the changes you've made to the module.
    I would also prefer to remove unused form fields from the html code instead of just hiding them in cascading styles.
    But I've found an issue: if I split a form into two blocks and set it to remove unused fields instead of just to visually hiding them, then changing the state of one form (e.g. ticking the checkbox) will clear the previous state of the second form (e.g. filled input).

  • πŸ‡³πŸ‡ΏNew Zealand dieuwe Auckland, NZ

    Not sure how feasible it is to merge multiple form states behind the scenes.

    I would put that down as a bit of a blocker to have the module fully support this feature, although the patch as it stands is very useful for some particular use cases.

  • πŸ‡ΊπŸ‡ΈUnited States chrisolof

    @rob.sipek, it sounds like for your use-case you'd need to stick with the default, "Visually hide" filter removal strategy so that current filter values are maintained regardless of which block's form is submitted. In your use-case that hidden markup is necessary as it makes that behavior possible.

    In some of my use-cases I do not need or want the hidden filters' current selections maintained, so the "Remove" strategy is a better fit (for example I have a search box that always initiates a fresh search - current deeper filtering choices are totally unnecessary and not desired in that block).

    Maybe a little help text under the 'Filter removal strategy' field and options would make it easier for users to determine which strategy is right for their needs. Example:

    Filter removal strategy
    - Visually hide
       Allows for current selections/values in hidden filters to be maintained through submit.
    - Remove
       Less markup, but only values from the visible filters in the form are submitted.

    Keep the default, "Visually hide", if you're unsure or the "Remove" strategy is not working for you.

Production build 0.71.5 2024