Problems with Select2 #8427
Unanswered
GBeushausen
asked this question in
1. Help
Replies: 1 comment
-
Have you tried to init the select2 via AlpineJS? That's what I do, move the init part into alpinejs.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
i have a select with over 150 elements to choose from, so i want to use select2 so that the user can search through the elements. However i've got a component which first only displays pure text. only if the user clicks on a button, the text get's transformed into a form.
I'm implementing this with a variable $editMode that is false by default but becomes true on that button press. In my blade template i have an if statement that displays the form if $editMode is true.
The problem is in this configuration i cannot add a script tag below the component to initialize select2 and handle the changed event, because the Javascript doesn't get executed. it would only work if i showed the form directly on page load.
So my workaround was to use jquery and run the code on the press of the edit Button. Which works halfway. Now the select2 get's initializes, but the selected value doesn't get saved. I've read that wire:model doesn't work on select2. So i've added a hidden field with wire:model for that value and i set the value from select2's change event to the hidden field.
But now the data from the hidden field doesn't get saved by livewire. only if i would enter the value by hand, but it doesn't save the value if it's changed by JQuery. I've already tried to trigger the "Input" or "change" event, but Livewire will not save the data.
What can i do to get it running?
Beta Was this translation helpful? Give feedback.
All reactions