2016-03-05 86 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();」'不起作用,但感謝您嘗試 –