hotwired / hotwire-rails

Use Hotwire in your Ruby on Rails app
https://hotwired.dev
MIT License
971 stars 27 forks source link

Form submissions within frames #31

Closed scottbarrow closed 3 years ago

scottbarrow commented 3 years ago

I have a form wrapped in a turbo_frame tag which is being submitted in a stimulus controller following some UI manipulation

formTarget.submit() submits the request as @string="text/html", @symbol=:html, @synonyms=["application/xhtml+xml"]>

Rails.fire(this.dashboardFiltersFormTarget, 'submit') submits the request as @string="text/vnd.turbo-stream.html", @symbol=:turbo_stream, @synonyms=[]> However, from what I understand this uses UJS?

Can anyone confirm if this is a bug or is using Rails.fire the intended way to submit the form within a frame

javan commented 3 years ago

Use formTarget.requestSubmit() instead of formTarget.submit(), which doesn’t dispatch a “submit” event among other things. See https://github.com/hotwired/turbo/issues/97#issuecomment-757224391 for a more detailed explanation. ✌️