Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retain persistent params when searching and filtering #61

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/views/trestle/search/_search.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
<% if admin.searchable? %>
<div class="searchbox">
<%= form_tag admin.path, method: :get, data: { turbo_frame: "main" } do %>
<%= serialize_persistent_params except: :q %>

<div class="input-group">
<%= label_tag :q, icon("fas fa-search"), class: "input-group-text" %>

<%= search_field_tag :q, params[:q], class: "form-control", autocomplete: "off", placeholder: admin.t("search.placeholder", default: "Search") %>

<%= link_to icon("fas fa-times"), admin.path, class: "btn btn-clear-search", data: { turbo_frame: "main" } if params[:q].present? %>
<%= link_to icon("fas fa-times"), persistent_params.except(:q), class: "btn btn-clear-search", data: { turbo_frame: "main" } if params[:q].present? %>
</div>
<% end %>
</div>
Expand All @@ -16,9 +18,7 @@
<% if admin.filterable? %>
<div class="search-filters">
<%= form_for admin.filters, as: :f, url: admin.path, method: :get, builder: Trestle::Form::Builder, html: { id: nil, class: nil, data: { turbo_frame: "main" } } do |f| %>
<% persistent_params.each do |k, v| %>
<%= hidden_field_tag k, v unless k == "f" %>
<% end %>
<%= serialize_persistent_params except: :f %>

<button type="button" class="btn <%= admin.filters.active(params).any? ? "btn-warning" : "btn-info" %>" data-controller="search-filters"><%= icon("fa fa-filter") %></button>

Expand Down