2016-03-05 88 views
0

有没有办法点击collection_radio_button表单会自动提交?collection_radio_button自动提交?

这样他们不必点击提交按钮,它只是自动发生。

<%= simple_form_for(@challenge) do |f| %> 
    <%= f.text_field :action %> 
    Or choose a featured challenge: 
    <%= f.collection_radio_buttons :action, [['Lose 10 Pounds','Lose 10 Pounds'], ['Exercise','Exercise'], ['Quit Smoking','Quit Smoking'], ['Run a 5K','Run a 5K'], ['Meditate','Meditate'], ['Visit Rome','Visit Rome'], ['Read a Chapter','Read a Chapter'], ['Walk 10,000 Steps','Walk 10,000 Steps'], ['Study a Foreign Language','Study a Foriegn Language'], ['No T.V.','No T.V.'], ['Backpack through Europe','Backpack through Europe'], ['Journal','Journal'], ['Go Vegetarian','Go Vegetarian']], :first, :last %> 
    <%= f.submit %> 
<% end %> 
+0

你应该可以做类似'<%= f.collection_radio_buttons:action,[['丢失10磅',...],:first,:last,onclick:'getElementById(“myForm”)。 submit()'%>' – MZaragoza

回答

3

你可以试试这个...

$('input[type=radio]').on('change', function() { 
    $(this).closest("form").submit(); 
}); 

的属性选择用在这里,你可能想改变这种状况的一类或某事更具体的为您的需求。

0

您可以使用onchange: "this.form.submit();"

<%= f.collection_radio_buttons :action, [['Lose 10 Pounds', bla bla bla], :first, :last, onchange: "this.form.submit();" %> 
+0

'“this.form.submit();”'不起作用,但感谢您尝试 –