2

I have one form but because of the design I can't use the same button on the mobile and web. I created two buttons, one is hidden on the mobile, one on desktop. However, one of them does not work.

Is there a way to have two submit buttons that do the exact same thing? I found lots of examples where two submit buttons do different thing. Mine looks something like this:

<%= form_tag form_path, class: "form", method: "GET" do %>
  <%= check_box_tag(:pet_dog) %>
  <%= label_tag(:pet_dog, "I own a dog") %>
  <%= check_box_tag(:pet_cat) %>
  <%= label_tag(:pet_cat, "I own a cat") %>

  <%= button_tag class:"mobile button" do%>
    SUBMIT
  <% end %>

  <%= button_tag class:"desktop button" do%>
    SUBMIT
  <% end %>
<% end %>
1
  • 1
    Which one doesn't work? What happens if you remove the working button, does the non-working button start working? Is the code different for one versus the other? Maybe there's something wrong with the submit code for one of them? Commented Feb 25, 2018 at 10:51

2 Answers 2

0

Try adding an id for your form:

form_tag form_path, class: "form", id: "my_form" method: "GET"

And add form attribute to your buttons:

<%= button_tag class:"mobile button", form: "my_form" do%>
  SUBMIT
<% end %>

<%= button_tag class:"desktop button", form: "my_form" do%>
  SUBMIT
<% end %>
Sign up to request clarification or add additional context in comments.

Comments

0

You can install: https://github.com/fnando/browser And try to use:

<%= button_tag class: "#{browser.mobile? ? 'mobile' : 'desktop'} button" do%>
  SUBMIT
<% end %>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.