DEV Community

Discussion on: Instant search with Rails 6 and Hotwire

Collapse
 
superails profile image
Yaroslav Shmarov

In a Rails 7 scenario where we don't have

import Rails from "@rails/ujs";
Enter fullscreen mode Exit fullscreen mode

, how would you do

      Rails.fire(this.formTarget, 'submit')
Enter fullscreen mode Exit fullscreen mode

?

Collapse
 
davidcolbyatx profile image
David Colby • Edited

Great question! If you're not using ujs, you can replace Rails.fire(this.formTarget, 'submit') with this.formTarget.requestSubmit(). I haven't thoroughly tested that change but it should work okay.

You might want to consider a polyfill, since requestSubmit() isn't supported on IE and Safari yet: caniuse.com/mdn-api_htmlformelemen...

To replace rails/ujs, you can consider mrujs, but mrujs doesn't currently support Rails.fire

Collapse
 
halfbloody profile image
Jens

Apparently, the polyfill for requestSubmit is part of Turbo now, so no reason to worry: github.com/hotwired/turbo/pull/439