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

后端 未结 5 1287
逝去的感伤
逝去的感伤 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:14

    I'm sorta new to this but here goes...

    rails.js (the jquery one at least) defines the following function to catch and submit forms:

    $('form').live('submit.rails', function(e) { ... });
    

    If you use the following it should trigger the same function (and if :remote => true, then it wont cause a page reload):

    $("#").trigger("submit.rails");
    

    So, if you wanted to submit your form on a select change for example, you could set the above trigger call to the select's :onchange I would imagine.

提交回复
热议问题