Open tagliala opened 1 year ago
Describe the bug destroy does not respect selected value. This causes issues when using with libraries like Turbo and Stimulus, where you want to destroy() when leaving the page or disconnecting the controller
destroy
selected
destroy()
To Reproduce Steps to reproduce the behavior:
Expected behavior Option 3 (selected) selected
Option 3 (selected)
Screenshots n/a
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context Related to #1055
As a workaround for simple inputs, I'm using this in the disconnect() controller
disconnect()
disconnect () { // FIXME: workaround for Choices-js/Choices#1088 const selectedValues = this.choices._currentState.items.map((item) => item.value) this.choices.destroy() selectedValues.forEach((selectedValue) => { const option = this.choicesTarget.querySelector(`option[value="${selectedValue}"]`) if (!option) { return } option.setAttribute('selected', 'selected') }) }
I've run into this problem too. Would be great to have a way to destroy() and keep selected values.
Describe the bug
destroy
does not respectselected
value. This causes issues when using with libraries like Turbo and Stimulus, where you want todestroy()
when leaving the page or disconnecting the controllerTo Reproduce Steps to reproduce the behavior:
Expected behavior
Option 3 (selected)
selectedScreenshots n/a
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context Related to #1055
As a workaround for simple inputs, I'm using this in the
disconnect()
controller