Skip to content

Commit

Permalink
Fire native change event in select controller
Browse files Browse the repository at this point in the history
  • Loading branch information
spohlenz committed May 11, 2024
1 parent 79cb256 commit c3e002f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/assets/bundle/trestle/bundle.js

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions frontend/js/controllers/select_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,24 @@ $.fn.select2.defaults.set('dropdownCssClass', function (el) {
export default class extends ApplicationController {
connect () {
$(this.element).select2(this.options)

$(this.element).on('change.select2', (e) => {
if (!e.originalEvent) {
e.preventDefault()

const nativeEvent = new CustomEvent('change', {
bubbles: true,
cancelable: true
})

e.target.dispatchEvent(nativeEvent)
}
})
}

disconnect () {
$(this.element).select2('destroy')
$(this.element).off('change.select2')
}

get options () {
Expand Down

0 comments on commit c3e002f

Please sign in to comment.