Views exposed filter

Created on 25 January 2025, 3 months ago

Before issue

This is a nice module that works very fast with a large number of terms (approximately 150,000, with a maximum depth of 6).

Problem/Motivation

What development status for Views exposed filters?
Because, HTS doesn't appear on exposed filters, even then I enable "Has term" or just term field.

Custom solution

I want to use it as exposed filter in views with custom entity on Search API view.
Taxonomy term: "Category" field, entity is "custom" entity.

I try next:
Category autocomplete filter added (hidden by CSS), and HTS global filter (visible).
Then on exposed submit I'll catch HTS values and put to Category filter (so search happen on Category with all depths).

For that I implement next code, to enable your widget in my view:
/**
* Implements hook_views_data_alter().
*/
function CUSTOMMODULE_views_data_alter(array &$data) {
// Exposed filter HTS widget defined globally:
$data['views']['category'] = [
'title' => t('Category filter'),
'filter' => [
'title' => t('Category filter'),
'help' => t('Provides a HTS filter for category field.'),
'field_name' => 'category',
'id' => 'hts_taxonomy_index_tid',
],
];
}

It shows HTS filters with correct settings.

But problems:
1. Children elements filled with all terms on current level - looks like it doesn't follow selected parent.
2. Also, there's no #ajax events - then I change TRUE to FALSE, I got count of errors for next call:
$this->formElement($element, TRUE, $settings, $inputs) in HtsTaxonomyIndexTid.php

Can you provide any advices?

💬 Support request
Status

Active

Version

1.0

Component

Code

Created by

🇷🇺Russia nikit

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

Comments & Activities

  • Issue created by @nikit
  • 🇪🇸Spain cesarmsfelipe

    During debugging, your solution (use a hidden category field and synchronise it with the HTS values) is valid. However, make sure that the synchronisation occurs before executing the query, so that the correct filters are applied.

    Let me know if this can help you or you need further clarification.

  • 🇷🇺Russia nikit

    Thank you for quick answer!
    The current problem isn't about catching submit data.
    Problem is exposed HTS select inputs - children elements filled with all children.
    Let me show how it's work now:

    Top select element #1 filled:
    - parent 1
    - parent 2 (this is selected)

    Child select element #2 filled with:
    child 1 of parent 1
    child 2 of parent 1
    child 1 of parent 2
    child 2 of parent 2
    child 3 of parent 2

    But select element #2 should be:
    child 1 of parent 2
    child 2 of parent 2
    child 3 of parent 2

    Also, I didn't find there attached ajax events or js for calculating children for selected parents. Allchild elements prefilled with children elements (without parent dependancy).

Production build 0.71.5 2024