thanks bro, i was honestly confused by the livewire 3 updates, the method are so much different to implement select2 than the previous livewire version
Nice tutorial! But you don't need the document ready since Livewire will execute the script only when it's about to work on the component and instead of adding ID to the select element, I would use a data- attribute or a class instead (e.g data-select-input or .select-input) to avoid using names that can result in invalid selectors (e.g Postal Code) and the script will be like: const select = $wire.$el.querySelector('[data-select-input]'); // or $wire.$el.querySelector('.select-input'); $(select).select2(); $(select).on('change', function (event) { $wire.$set('value', event.target.value); });
Do you (anyone) know how to get it to select initialized values correctly? If in this example, you initialize public $selectedCountry = 2, the Select2 element won't display the correct country (although it will report the correct value in the console). Anyone have a fix?
Laravel Livewire Dependent Dropdown with Select2
thanks bro, i was honestly confused by the livewire 3 updates,
the method are so much different to implement select2 than the previous livewire version
It's a nice example. Thanks for that!
Thanks a lot tony for making this on my request 😊
Livewire v3 not working with multiple attribute. The multiple select is distorted. Please make a demo to demo multiple in livewire v3
Tks! Its posible use select2 in modal component?
Nice tutorial!
But you don't need the document ready since Livewire will execute the script only when it's about to work on the component and instead of adding ID to the select element, I would use a data- attribute or a class instead (e.g data-select-input or .select-input) to avoid using names that can result in invalid selectors (e.g Postal Code) and the script will be like:
const select = $wire.$el.querySelector('[data-select-input]'); // or $wire.$el.querySelector('.select-input');
$(select).select2();
$(select).on('change', function (event) {
$wire.$set('value', event.target.value);
});
hi tony, what is the reason why you don't like jquery?
Hi, how to get selected data and store it to database? I've added wire:model on select tag but always return null when I tried to get the data
Can u do it with TomSelect?
Can you do one for updating
thank you. need for multi select dropdown also.
thank you
Welcome!
Do you (anyone) know how to get it to select initialized values correctly? If in this example, you initialize public $selectedCountry = 2, the Select2 element won't display the correct country (although it will report the correct value in the console).
Anyone have a fix?
Please don't use select2. There are better alternatives these days without jquery
Examples of these alternatives ?
tom select, virtual select, choicesjs
yeah tom select is good and better of select2 for me