Rails 3: How to trigger a form submission via javascript?

后端 未结 5 1303
逝去的感伤
逝去的感伤 2020-12-30 08:25

I have a form that for the most part just submits as a normal form, so I don\'t want to set in the form_tag the :remote => true option.

However, under certain circum

5条回答
  •  长发绾君心
    2020-12-30 09:07

    I just tried this which definitely works, if the form has remote => true, just remove the data-remote attribute to submit normally w/ javascript ie

    $('input').click(function(){ $('#form').removeAttr('data-remote') });
    

    I'm guessing the opposite would probably work ie if the form doesn't have remote => true just do

    $('input').click(function(){ $('#form').attr('data-remote',true)});
    

提交回复
热议问题