I'm working on a search form that has two disperate inputs: there is 1) a search box and some dropdown selects and 2) several buttons with preset filters.
The first (search box and dropdowns) is a component which is a form, with all the search and filter options inside of it.
<%= c :filter, :search, query_params: @table.query_params %>
<div class="row">
<div class="col-xs-12 col-md-3">
<%= c :table_filter, :select,
[
name: :status,
options: status_select_box(),
operator: "eq",
table: @table
]
%>
</div>
<% end %>
The second, the preset filters, sit above the search box and display a count of how many results they will return @count
and when clicked filter based on the params passed to their @path assigns.
On the search page:
<%= render "_btn.html",
[
path: search_path(@conn, :index, %{mode: "eq:filter"}),
count: @count,
label: "Filter 1"
]
%>
_btn.html.eex
<%= link to: @path, class: "btn" do %>
<%=
#this is pusdo code for the button, there is a bit more logic to
how it is displayed but essentially it just shows a label and the count
@label @count
%>
<% end %>
Both of these forms work fine, the issue is that if someone clicks one of the preset filters, the params will not persist if they go and select a dropdown. I'm wondering what the most concise way of ensuring that the query params will persist between the two forms.