Leopd
Leopd

Reputation: 42717

Rails remote form submit through javascript

I'm trying to create a very small simple form that edits a single checkbox, and submits automatically with AJAX when the checkbox is modified. Here's the code, which other SO questions imply should work:

    <%= form_for(workitem, :remote => true) do |f| %>
      <%= f.check_box :is_complete, :onchange => 'this.form.submit()' %>
    <% end %>

The problem is that this results in a full page HTML submit, rather than an AJAX submit. How do I trigger an AJAX submit?

Upvotes: 3

Views: 4134

Answers (2)

Gopal S Rathore
Gopal S Rathore

Reputation: 9995

This is simply in Rails way :

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

find it here : same question

Upvotes: 1

Leopd
Leopd

Reputation: 42717

This seems to work:

$(this.form).submit();

Good 'ol jquery to the rescue.

Upvotes: 8

Related Questions