Can we connect action to target's click event?


#1

Hi

First, thanks creat Stimulus, it’s awesome.

I have form like below screenshot:

When file_field change, it will call method setting#finishUpload
In finishUpload of setting controller, it call this.sumbitTarget.click

Can we connect action to target’s click event?

Something like action: “change->setting@submitTarget.click” ?


#2

It looks like there is a syntax error in your controller, but you could also just make your form a target

<%= form_for @model, remote: true, data: { target: 'setting.form' } %>
export default class extends Controller { 
  static targets = ['form'];

  finishUpload(e) {
    this.formTarget.submit();
  }
}