2013-08-20 41 views
0

我的形式有一個無線電選擇字段功能:呼叫當用戶選擇一個選項

<div class="field"> 
    <%= f.label :sicherheit, "Verdacht auf" %> 
    <%= f.radio_button :sicherheit, 'V' %> 
    <%= f.label :sicherheit, "Zustand nach" %> 
    <%= f.radio_button :sicherheit, 'Z' %> 
    <%= f.label :sicherheit, "Ausschluss" %> 
    <%= f.radio_button :sicherheit, "A" %> 
    <%= f.label :sicherheit, "Gesicherte Diagnose" %> 
    <%= f.radio_button :sicherheit, "G" %> 
    </div> 

我想,當用戶選擇一個選項,行動ICD控制器驗證被稱爲!想象它更好,我需要類似的東西,鏈接到:

<%= link_to "#{g.nummer}", icd_validate_path(g), remote: true %> 

我希望你明白我想要什麼?謝謝!

+0

所以你說它需要驗證,當他們點擊單選按鈕或當他們提交表單時?如果它點擊驗證,我認爲你需要使用javascript – dax

+0

當用戶點擊一個單選按鈕,而不是當表單被提交時! –

+0

對不起,編輯 - 我的意思是,如果它驗證**點擊**你需要javascript(我想!) – dax

回答

0

我想你需要使用jquery進行AJAX調用,但要確保icd_validate_path(g)正確並在route.rb中定義,並且控制器響應js格式。

<script type="text/javascript"> 
$(function(){ 
    $('input[type="radio"]').click(function(){ 
     $.ajax({url: '<%= icd_validate_path(g) %>', data: {'value': $(this).val()}, success: function(data){ 
      alert('success'); 
      //do some your actions. 
     }}) 
    }); 
}); 
</script>