1

I know that if you just type something like <button>Something</button> outside a form_for in rails, it will create a useless button. But I want to create buttons within this form_for to be handled by JavaScript. Is there a way to create it?

Tomás Lima
  • 313
  • 2
  • 9

3 Answers3

1

This will create useless buttons that can be handled by JavaScript.

Plain HTML:

<input type="button" onclick="alert('Hello.')" value="Click Here" />

Rails:

<%= submit_tag "Click Here", :type => 'button', :onclick => 'alert("Hello.")' %>
johnsorrentino
  • 2,731
  • 1
  • 16
  • 21
0

If you're not looking for Rails to use it, why not just use the plain html inside the form_for?

<%= form_for @record do |f| %>

  ## inputs ##

  <button>Something</button>
  <%= f.submit %>

<% end %>
Helios de Guerra
  • 3,445
  • 18
  • 23
0

Check out this answer: How do I create multiple submit buttons for the same form in Rails?

<% form_for(something) do |f| %>
    ..
    <%= f.submit 'A' %>
    <%= f.submit 'B' %>
    ..
<% end %>
Community
  • 1
  • 1
ChrisBarthol
  • 4,871
  • 2
  • 21
  • 24