Support non-standard input types

Created on 2 April 2024, 3 months ago
Updated 23 April 2024, 2 months ago

Problem/Motivation

We've encountered an issue where the functionality to clear all filters does not work as expected for forms containing Select2 elements. When attempting to use the clear all filters action, all filters should reset to their initial state. However, Select2 elements retain their selected values, which leads to a confusing user experience and requires manual intervention to reset these filters. This behavior deviates from the expected functionality where all form elements, including those enhanced by Select2, are reset.

Steps to reproduce

  1. Navigate to the page containing the filter form enhanced with Select2 elements.
  2. Apply several filters, ensuring at least one is a Select2 element with one or more options selected.
  3. Click the "Clear all" button designed to reset all filters.
  4. Observe that while most filters reset to their default state, the Select2 elements do not clear out and retain their previously selected values.

Proposed resolution

Support non-standard input types by having active filters check the input element for a activeFilterRemove method and call it if it exists instead of using the module-supplied removal logic.

Remaining tasks

  1. Develop a patch that introduces the necessary JavaScript adjustments.
  2. Test the patch to ensure it resolves the issue without introducing other side effects.

User interface changes

No direct changes to the user interface, but the clear all filters action will correctly reset Select2 elements, leading to a more intuitive and expected behavior.

API changes

A new activeFilterRemove method is available to provide custom remove logic for non-standard input types.

Data model changes

None required for this issue.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain cesarmsfelipe

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

Merge Requests

Comments & Activities

  • Issue created by @cesarmsfelipe
  • πŸ‡ͺπŸ‡ΈSpain cesarmsfelipe

    Attached is a patch that improves handling of Select2 elements when removing a specific active filter, rather than clearing all values. This patch specifically adjusts the behavior for 'select' type fields to check for Select2 data and properly filter out the value to be removed, maintaining the rest of the selections intact. This change aims to enhance the usability and functionality of the Active Filters module when used with Select2 elements provided by BEF.

    I've tested the patch on 1.0.0-rc2, and it successfully allows individual active filters to be removed from Select2 fields without affecting other selected values.

    I would appreciate further testing and review.

  • Assigned to cesarmsfelipe
  • Status changed to Needs review 3 months ago
  • First commit to issue fork.
  • πŸ‡ΊπŸ‡ΈUnited States benabaird

    Thanks for the report cesarmsfelipe! I'm reluctant to add checks for specific input types beyond standard HTML ones as we'd open up a situation in which we end up supporting a lot of different libraries. But I also agree that the module does need a way to support these input types.

    To that end I've added a way to provide a custom removal method for active filters. Would try the patch for the issue branch and see if that works for you? Here's the documentation on how to implement.

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

    Editing the issue title and summary to reflect the need for a way to provide custom removal methods on inputs.

  • Merge request !8Add support for custom removal callbacks. β†’ (Merged) created by benabaird
  • Assigned to benabaird
  • πŸ‡ͺπŸ‡ΈSpain cesarmsfelipe

    Thanks benabaird, I've tested the custom removal method as per the documentation you provided, and it worked correctly for me.

  • Status changed to RTBC 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States benabaird
  • Pipeline finished with Skipped
    3 months ago
    #141732
  • Status changed to Fixed 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States benabaird

    Excellent, glad this solution works for you, thank you for the confirmation!

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

Production build 0.69.0 2024