0

I have two forms on the same page.

The first one:

  <%= form_with url: admin_users_path, method: :get,
                class: "d-none d-md-inline-block me-auto w-100",
                data: {
                  autosave_delay_value: 300,
                  controller: "autosave",
                  turbo_action: "advance",
                  turbo_frame: "users"
                } do %>
    <div class="input-group input-group-merge">
      <%= text_field_tag "search", params[:search],
                                   class: "form-control bg-white",
                                   data: { action: 'keyup->autosave#save' },
                                   placeholder: t("search", scope: "shared.action_name") %>
      <span class="input-group-text bg-white">
        <%= svg_icon("search-1", height: 16) %>
      </span>
    </div>
  <% end %>

And second one:

  <%= form_with url: admin_users_path, method: :get,
                class: "d-none d-md-inline-block me-auto w-100",
                data: {
                  controller: "autosave",
                  turbo_action: "advance",
                  turbo_frame: "users"
                } do %>
    <%= check_box_tag :confirmed, true, false,  data: { action: 'autosave#save' }%>
  <% end %>

To display filtered data i use:

  <%= turbo_frame_tag "users" do %>
    <div class="table-responsive">
      <table class="table table-sm table-hover align-middle table-edge table-nowrap mb-0">
        <thead class="thead-light">
          <tr>....
          ....

If I search for a user by name in the first form, for example, type "John" the url looks like this: http://localhost:3000/admin/users?search=john. If I check the box in the second form the address changes to: http://localhost:3000/admin/users?confirmed=true This way I lose the search parameter.

The page is not reloaded, I just change the results.

How to pass this parameter between these forms?

Regards

Rails 7, Hotwire, Stimulus, Ruby 3.0.0, turb_frame_tag

plewas
  • 229
  • 1
  • 3
  • 11
  • is there any reason why you need 2 forms? Seems like rather design issue. If you move your confirmed checkbox to first form all will be working as you expected and then drop second form. – zhisme Jan 23 '23 at 13:04
  • The first form is a search by name. It is located at the top of the page like the main search bar. The second form with search by status, type, etc. is located on the sidebar. (https://getbootstrap.com/docs/5.2/components/offcanvas/#static-backdrop) Therefore, these are two separate forms. In the meantime, I found a solution on the client side. I use javascript to set the value of the hidden fields in the opposite form. I don't know if this is a good solution, but it seems to work. Translated with www.DeepL.com/Translator (free version) – plewas Jan 23 '23 at 14:26

0 Answers0