Stimulus: Submitting Remote Forms?

Created on 2 Feb 2018  路  2Comments  路  Source: hotwired/stimulus

Hi there,

First of all: Thanks for sharing this library, it looks very promising and like a "missing piece of the puzzle" 馃憤

I am currently trying to integrate it in an existing Rails application with remote forms but I am struggling with making those play nicely with stimulus. When calling submit(), it seems to ignore the remote attribute and submits the form without XHR:

= simple_form_for @some_object, url: "some-url", html: {method: :get, data: {'controller' => 'filter'}}, remote: true do |f|
  = f.input :query, ..., input_html: {data: {action: "input->filter#update propertychange->filter#update"}}
  = f.button :submit

filter_controller.js:

import { Controller } from "stimulus"

export default class extends Controller {
  update() {
    this.element.submit();
  }
}

The update() method is called correctly when the input changes but it does submit the form with a regular HTTP request instead via XHR. It worked just fine with the previous jQuery-based approach. I tried it with jquery_ujs as well as rails-ujs.

Any ideas what might cause this?

Thanks!

Most helpful comment

Try making your submit button a target and click()ing it instead: this.submitTarget.click().

We鈥檝e just set up a new forum for questions like these: http://discourse.stimulusjs.org

Would you mind re-posting your question there if that doesn't solve your issue? Thank you!

All 2 comments

Try making your submit button a target and click()ing it instead: this.submitTarget.click().

We鈥檝e just set up a new forum for questions like these: http://discourse.stimulusjs.org

Would you mind re-posting your question there if that doesn't solve your issue? Thank you!

Awesome, works! Thanks for the swift help!

Was this page helpful?
0 / 5 - 0 ratings