List filters anomaly

While checking and tidying some lists, I found two that had no user controlled filters, but nonetheless showed a “Clear filters” button (without a “Filters” button). The lists had non-default settings in “Details | Filters”, including “No” in “Details | Filters | Filters”; it is probable that when working on them some time ago I had added some filters and then removed them. All elements had “List view settings | Filters | Filter type” set to “None”.

In each list I changed “Details | Filters | Filters” from “No” to “Above”; the “Clear filters” buttons no longer appeared. It is obviously not much of a problem, but presumably they should not appear when the setting is “No”.

Fabrik 4.0delta, Joomla 4.3.3, PHP 8.0.29.
 
You can have e.g. query string filters and with "No" you won't have any filter block with a "Clear filters".
That's the reason why it is displayed.
You can change
C:\xampp8\htdocs\j4h40\components\com_fabrik\views\list\tmpl\bootstrap\default_buttons.php line 51
to
if (($this->showClearFilters && (($this->filterMode === 3 || $this->filterMode === 4)) || $this->bootShowFilters == false && $this->gotOptionalFilters))
which should show the button only IF there was some filtering.
 
I tried making the change, but it did not help. As it is not a serious problem, I left it for a while, but have now had another look.

The code that shows the “Clear filters” button is in both
components/com_fabrik/views/list/tmpl/bootstrap/default_buttons.php and
components/com_fabrik/views/list/tmpl/div/default_buttons.php​
at line 51:
PHP:
if (($this->showClearFilters && (($this->filterMode === 3 || $this->filterMode === 4)) ||
     $this->bootShowFilters == false)) :
It is always true if bootShowFilters is false, i.e. if Filter mode is “No” and there is no Table search all filter.
Also, it is true if there is at least one Element filter defined and Filter mode is “Under headings” or “Under headings (toggleable)”. (In the “Under headings (toggleable)” setting, it is true regardless of the toggle state.)

As I was getting somewhat confused, I checked, with the original code in place, what happens in the various filter modes for a form with element filters and for one with none. In each case, for mode zero, the action seems incorrect; the Clear filters button is displayed (and is active), despite there being no Filter button and no filters.

In addition, in mode 4 with element filters defined, although the Clear filters button is displayed correctly, it might be nice if it was hidden along with the filters themselves when they are toggled off, although in this case there is a filters button showing, so the Clear filters button does not look so odd. The mode 5 case is similar; the button could toggle off when the pop-up is open, although it only duplicates the clear filter link in the pop-up. After spending a while on this, I did not feel like digging into the Javascript to see if anything could be done to make a small improvement!

I would have included tables here, showing all states, but could find no way of doing so.

I also checked what happens when the Table search all filter is defined, both with and without element filters being defined. With the Table search all filter defined, in filter modes (including toggleable ones) where neither the Clear filters button nor the Clear filters link is displayed, the Clear filters button is not added (except in mode zero where it is currently added anyway, I think erroneously). I think it should be added in these cases.

The unwanted Clear filters button in filter mode zero appears to be due to the effect of bootShowFilters, so I had a look at that. The code for it is in
views/list/view.base.php at line 615:​
PHP:
$this->bootShowFilters = (count($fKeys) === 1 && $fKeys[0] === 'all') ||
     $this->filterMode === 0 ? false : true;
It is always true for modes other than “No” and it is always true if there is a Table search all filter. It is false only if there is no Table search all filter and the mode is “No”.

I found that bootShowFilters is used in
components/com_fabrik/views/list/tmpl/bootstrap/default.php
components/com_fabrik/views/list/tmpl/bootstrap/default_buttons.php and
components/com_fabrik/views/list/tmpl/div/default_buttons.php​
all at line 51. These are the places that cause display of the Clear filters button and bootShowFilters is used to determine when there is a table filter defined. Filter modes are checked in each place it is used and the check for mode zero in the code for bootShowFilters is counterproductive. bootShowFilters seems to be used nowhere else.

I suggest the code that sets it up could be revised to:
PHP:
$this->bootShowFilters = (count($fKeys) === 1 && $fKeys[0] === 'all');
and that the code in both
components/com_fabrik/views/list/tmpl/bootstrap/default_buttons.php and
components/com_fabrik/views/list/tmpl/div/default_buttons.php​
at line 51 be modified to:
PHP:
if ($this->showClearFilters && ($this->filterMode === 3 || $this->filterMode === 4) ||
     ($this->bootShowFilters && ($this->filterMode === 0 || $this->filterMode === 2 ||
     $this->filterMode === 5)) || (!$this->showClearFilters && $this->bootShowFilters)) :

When I tried these modifications, the various problems seemed to be solved and no new ones appeared, although my testing was not exhaustive.

I then noticed some discrepancies with what is displayed for the Table search all filter in the various modes; these occur with the original code as well as with my modifications. Having run out of time, I decided to report my findings so far to see if anyone has any comments; I will look further when I can find the time.
 
I keep getting a server error when I try to post a reply, so am now trying to send just the first paragraph.

I have realised that there were a few problems with the modifications suggested in my previous reply. When I looked at my system again, in some modes filters were not showing; presumably the checks that I had done earlier were too limited.
 
Still getting a server error, so now trying part of it.

I have realised that there were a few problems with the modifications suggested in my previous reply. When I looked at my system again, in some modes filters were not showing; presumably the checks that I had done earlier were too limited.

I found that I had not checked properly on every place where bootShowFilters is used. In

components/com_fabrik/views/list/tmpl/bootstrap/default.php​

which does much of the rendering of the list, it is used to control whether filters appear. The code, at line 51, is:
PHP:
if ($this->showFilters && $this->bootShowFilters) :
    echo $this->layoutFilters();
endif;
 
And the rest - there was one bad character in some code.

The code for showFilters is in:

components/com_fabrik/views/list/view.base.php at line 621:​
PHP:
$this->showFilters = $model->getShowFilters();
and:

components/com_fabrik/models/list.php at line 1183​
PHP:
return (count($filters) > 0 && $filterMode !== 0) && $this->app->getInput()->get('showfilters', 1) == 1 ? true : false;
It is true IF $this->app->getInput() has 1 for 'showfilters' AND (there are some filters AND filterMode is not “No”).

The (original) code for bootShowFilters is in:

views/list/view.base.php at line 615:​
PHP:
$this->bootShowFilters = (count($fKeys) === 1 && $fKeys[0] === 'all') || $this->filterMode === 0 ? false : true;
It is true IF there is a search all filter OR filterMode is not “No”.
It is false IF there is not a search all filter AND filterMode is “No”.

In default.php:
Filters are rendered IF showFilters is true AND bootShowFilters is true.
Filters are not rendered IF 'showfilters' is not 1 OR there are no filters OR filterMode is “No”
OR (there is not a search all filter AND filterMode is “No”).

Therefore it seems that the use of bootShowFilters in deciding whether to render filters is redundant; it could be removed. It took a while to get my head around the logic of this, but I think I am correct.

Therefore, in components/com_fabrik/views/list/tmpl/bootstrap/default.php;
PHP:
if ($this->showFilters && $this->bootShowFilters)
can be changed to:
PHP:
if ($this->showFilters)
(In the alternative components/com_fabrik/views/list/tmpl/div/default.php, the existing code already has this form.)

This change, together with the two in my previous reply, seems to fix the problem of an unwanted Clear filters appearing in filter mode zero. I made quite a few checks for the various filter modes with and without Search all and found nothing untoward.

While doing this, I did notice a few problems with Search all, which also seem to occur with existing code:

Clear filters does not show if filter mode is 0 (No) and can only be cleared by deleting contents of box. This doubtless is caused by my mods and could probably be corrected. I found nothing obvious to check and it is probably necessary to get the list’s setting of Search all, but I do not know where to look for it.

If there are no element filters and the filter mode not 0 (No), Clear filters appears.

Where a list is a “detail” of another (where it is in the outro of a form) with records selected by reference to its parent, enabling Search all, both with and without any elements enabled for it, in some cases causes strange effects including:

In filter mode 0 (No), if value is entered in Search all box (with return), it does the filtering, but clears the “detail” filter so the selection is done from all records. If the value is deleted (with return), the “detail” filter remains off and all records are shown.​

When the filter mode is not 0 (No), “Search:” appears with a blank beside it; Clear filters link appears. If a value is entered in the Search all box (with return), the effect is the same as mode 0, including deleting it, but if Clear filters is used instead of deleting, the Search all filter is cleared, but “detail” filtering is restored.​

(I also noticed that Search all does not work with dropdowns; presumably it searches by value, not text, unlike element filters, which do work by text.)
 
I have just realised that there was a error in my previous post, stating that the new modification was in addition to the two proposed earlier. If fact, only one of the earlier modifications is required, so the two modifications that I am now suggesting are, in both:
components/com_fabrik/views/list/tmpl/bootstrap/default_buttons.php​
and:
components/com_fabrik/views/list/tmpl/div/default_buttons.php​
that line 51 be modified from:
PHP:
if (($this->showClearFilters && (($this->filterMode === 3 || $this->filterMode === 4))  ||
    $this->bootShowFilters == false)) :
to:
PHP:
if ($this->showClearFilters && ($this->filterMode === 3 || $this->filterMode === 4) ||
    ($this->bootShowFilters &&
    ($this->filterMode === 0 || $this->filterMode === 2 || $this->filterMode === 5)) ||
    (!$this->showClearFilters && $this->bootShowFilters)) :
and, in:
components/com_fabrik/views/list/tmpl/bootstrap/default.php;​
that line 51 be modified from:
PHP:
if ($this->showFilters && $this->bootShowFilters) :
to:
PHP:
if ($this->showFilters) :
I hope I have it right now.
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top