Rails.fire unable to submit form

2.2k Views Asked by At

I want to submit a remote form using JS and I am using Rails 5.2.0.

The form looks like below:

<form class="new_post" id="my_form" action="/posts" accept-charset="UTF-8" data-remote="true" method="post">
  <input name="utf8" type="hidden" value="✓">
  <input type="hidden" name="authenticity_token" value="UxvP0R6bSbbzwuXyTj/hTCvf6Tmdzqr1j5mQVy9ZaaoBBd5LhkS3o4y3iXKWLfZzQ0pgATbOmvh8/cj2YAXy3Q==">
  <div class="form-group">
    <label class="form-label" for="title">Name</label>
    <input class="form-control" type="text" name="post[title]" id="post_title">
  </div>
</form>

As per https://github.com/rails/rails/issues/29546 , I should be able to submit a form using Rails.fire($('#my_form')[0], 'submit'); .

However in my case the above line is simply returning false, hence it is not submitting the form.

The above code was working just fine when I was using Turbolinks 5. It has stopped working when I removed Turbolinks from the application.

Any help will be highly appreciated. Thanks

1

There are 1 best solutions below

0
On

I debugged the rails-ujs, got to know the issue is being created by pace.js which I have added to the project.

Once I removed it, everything started working fine.