Form is submitted when I click on the button in form. How to avoid this?

后端 未结 3 605
天命终不由人
天命终不由人 2020-11-27 04:26

I use twitter-boostrap and I\'d like to use these radio-buttons in my form. The problem is when I click on any of these buttons, the form is immediately submitted. How to av

3条回答
  •  天命终不由人
    2020-11-27 05:24

    You can do this directly using rails form helper also by specifying type as an option to "button":

    <%= form_for @product do |f| %>
        
    <%= f.label :type, :class => 'control-label' %>
    <%= f.button "Button_1", type: "button", class: "btn" %> <%= f.button "Button_2", type: "button", class: "btn" %>
    <%= f.submit nil, :class => 'btn btn-primary' %> <%= link_to 'Cancel', products_path, :class => 'btn' %>
    <% end %>

提交回复
热议问题