Submitting Rails Form on a Radio Button Selection

后端 未结 3 1162
深忆病人
深忆病人 2021-02-11 06:55

I have the following rails form (which works) but I want to remove the submit_tag and have the form submit as soon as a radio button selection is made. How do I do that?

<
3条回答
  •  一向
    一向 (楼主)
    2021-02-11 07:25

    So I have found the precise solution (thanks for the input guys, it helped me redefine my Google searches). Everyone was on the right track, but none were spot on.

    All that was needed was to add 'false, :onclick => "this.parentNode.submit();"' to the radio_button_tag form helper. The false is selected or not, and the rest is obvious.

    The correct solution now looks like:

    <% form_tag({ :controller => "votes", :action => "create", :id => @item.id } ) do  %>
        <% for i in 1..10 do %>
          <%=  radio_button_tag :rating, i, false, :onclick => "this.parentNode.submit();" %> <%=h i %> 
        <% end %>
    <% end %>
    

提交回复
热议问题