Skip to content

Commit

Permalink
Merge pull request #2524 from pallets-eco/fix/bs4-filter-changes
Browse files Browse the repository at this point in the history
Fix `Apply` filter button show/hide
  • Loading branch information
samuelhwilliams authored Sep 15, 2024
2 parents 0f89ba8 + f82d1d5 commit 829c8e7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
7 changes: 7 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

2.0.0a1
-------

Fixes:

* The `Apply` button for filters will show/hide correctly again

2.0.0a0
-------

Expand Down
16 changes: 10 additions & 6 deletions flask_admin/static/admin/js/bs4_filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ var AdminFilters = function(element, filtersElement, filterGroups, activeFilters
function removeFilter() {
$(this).closest('tr').remove();
if($('.filters tr').length == 0) {
$('button', $root).hide();
$('a[class=btn]', $root).hide();
$('button', $root).addClass('d-none');
$('.filters tbody').remove();
} else {
$('button', $root).show();
$('button', $root).removeClass('d-none');
}

return false;
Expand All @@ -42,7 +41,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
Expand All @@ -69,6 +68,11 @@ var AdminFilters = function(element, filtersElement, filterGroups, activeFilters
}
inputContainer.replaceWith($('<td/>').append($field));

// show "Apply Filter" button when filter input is changed
$field.on('input change', function() {
$('button', $root).removeClass('d-none');
});

return $field;
}

Expand Down Expand Up @@ -153,7 +157,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
Expand All @@ -166,7 +170,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);
Expand Down
2 changes: 1 addition & 1 deletion flask_admin/templates/bootstrap4/admin/model/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<input type="hidden" name="page_size" value="{{ page_size }}">
{% endif %}
<div class="pull-right">
<button type="submit" class="btn btn-primary" class="d-none">{{ _gettext('Apply') }}</button>
<button type="submit" class="btn btn-primary d-none">{{ _gettext('Apply') }}</button>
{% if active_filters %}
<a href="{{ clear_search_url }}" class="btn btn-secondary">{{ _gettext('Reset Filters') }}</a>
{% endif %}
Expand Down
Binary file modified flask_admin/translations/en/LC_MESSAGES/admin.mo
Binary file not shown.

0 comments on commit 829c8e7

Please sign in to comment.