From 6614753003d1544ed2ceb11b81ae555b0396c5b2 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Sun, 15 Sep 2024 12:10:02 +0100 Subject: [PATCH 1/2] Fix 'Apply' filter button visibility This became permanent visibly after #2501 because jQuery's show/hide methods work toggle inline styles for `display: none`, but that PR switched over to the `d-none` class from bootstrap. This patch adds/removes the `d-none` class now. :w --- doc/changelog.rst | 7 +++++++ flask_admin/static/admin/js/bs4_filters.js | 15 ++++++++++----- .../bootstrap4/admin/model/layout.html | 2 +- .../translations/en/LC_MESSAGES/admin.mo | Bin 6263 -> 6263 bytes 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 576bfd525..05f979f2f 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -1,6 +1,13 @@ Changelog ========= +2.0.0a1 +------- + +Fixes: + +* The `Apply` button for filters will show/hide correctly again + 2.0.0a0 ------- diff --git a/flask_admin/static/admin/js/bs4_filters.js b/flask_admin/static/admin/js/bs4_filters.js index 24e342ddc..dfab241e8 100644 --- a/flask_admin/static/admin/js/bs4_filters.js +++ b/flask_admin/static/admin/js/bs4_filters.js @@ -22,11 +22,11 @@ var AdminFilters = function(element, filtersElement, filterGroups, activeFilters function removeFilter() { $(this).closest('tr').remove(); if($('.filters tr').length == 0) { - $('button', $root).hide(); + $('button', $root).addClass('d-none'); $('a[class=btn]', $root).hide(); $('.filters tbody').remove(); } else { - $('button', $root).show(); + $('button', $root).removeClass('d-none'); } return false; @@ -42,7 +42,7 @@ var AdminFilters = function(element, filtersElement, filterGroups, activeFilters var $field = createFilterInput($inputContainer, null, selectedFilter); styleFilterInput(selectedFilter, $field); - $('button', $root).show(); + $('button', $root).removeClass('d-none'); } // generate HTML for filter input - allows changing filter input type to one with options or tags @@ -69,6 +69,11 @@ var AdminFilters = function(element, filtersElement, filterGroups, activeFilters } inputContainer.replaceWith($('').append($field)); + // show "Apply Filter" button when filter input is changed + $field.on('input change', function() { + $('button', $root).removeClass('d-none'); + }); + return $field; } @@ -153,7 +158,7 @@ var AdminFilters = function(element, filtersElement, filterGroups, activeFilters addFilter(name, filterGroups[name], false, null); - $('button', $root).show(); + $('button', $root).removeClass('d-none'); }); // on page load - add active filters @@ -166,7 +171,7 @@ var AdminFilters = function(element, filtersElement, filterGroups, activeFilters // show "Apply Filter" button when filter input is changed $('.filter-val', $root).on('input change', function() { - $('button', $root).show(); + $('button', $root).removeClass('d-none'); }); $('.remove-filter', $root).click(removeFilter); diff --git a/flask_admin/templates/bootstrap4/admin/model/layout.html b/flask_admin/templates/bootstrap4/admin/model/layout.html index 6bd192f65..936bfd1d4 100644 --- a/flask_admin/templates/bootstrap4/admin/model/layout.html +++ b/flask_admin/templates/bootstrap4/admin/model/layout.html @@ -46,7 +46,7 @@ {% endif %}
- + {% if active_filters %} {{ _gettext('Reset Filters') }} {% endif %} diff --git a/flask_admin/translations/en/LC_MESSAGES/admin.mo b/flask_admin/translations/en/LC_MESSAGES/admin.mo index 94b61f16bfdc72324d7c8ddd085ba79d05ca0b6d..91e2551edf3ece9f6027b9317de0a4a4720e0d61 100644 GIT binary patch delta 14 Vcmexv@ZDeoj{u|DW?q3T4gf291e5>( delta 14 Vcmexv@ZDeoj{u|TW?q3T4gf231d{*& From f82d1d59fa335cc89a84dbc4b2097a1c806a2f0b Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Sun, 15 Sep 2024 12:10:21 +0100 Subject: [PATCH 2/2] Don't (try to) hide the `reset filters` button This lookup doesn't work because it's doing a full "class equals" check, but the class is "btn btn-primary". Also, because the page doesn't refresh when individual filters are removed, if the "Reset filters" button is removed altogether then users have no way to "apply" the removal of all filters. So we actually need to keep this button around when the last filter is removed (it remains a probably-weird user interaction, but I'm maintaining that for now - not because it's good, but just to not change the existing behaviour) --- flask_admin/static/admin/js/bs4_filters.js | 1 - 1 file changed, 1 deletion(-) diff --git a/flask_admin/static/admin/js/bs4_filters.js b/flask_admin/static/admin/js/bs4_filters.js index dfab241e8..248b7b65d 100644 --- a/flask_admin/static/admin/js/bs4_filters.js +++ b/flask_admin/static/admin/js/bs4_filters.js @@ -23,7 +23,6 @@ var AdminFilters = function(element, filtersElement, filterGroups, activeFilters $(this).closest('tr').remove(); if($('.filters tr').length == 0) { $('button', $root).addClass('d-none'); - $('a[class=btn]', $root).hide(); $('.filters tbody').remove(); } else { $('button', $root).removeClass('d-none');