/stimulus-turbolinks-select2

A demo on how to fix Turbolinks conflicts with jQuery plugins (like Select2) using Stimulus

Primary LanguageRuby

Stimulus + Turbolinks and Select2

A demo showing how to make jQuery plugins (like Select2) work with Turbolinks, using Stimulus as the loader/unloader of the plugin.

  • Stimulus (by Basecamp) adds listeners on elements as they appear on the page.
  • Turbolinks (also by Basecamp) loads the next page via pjax.
  • Select2 upgrades select elements with stuff like multi-selection, typeahead, etc.

Watch the video

Used as the demo in this presentation, given at the Ottawa Ruby meetup on January 17, 2018.
Turn Turbolinks Back On: Stimulus Brings the Sprinkles.

Note: the video shows off stimulus@0.9.0 syntax and this demo now runs 1.0, but the difference is only in calling the target elements. this.select is now this.selectTarget, and it's no longer needed to have the get select() getter.

See also:

-- Pascal Laliberté