Download the PHP package laspi94/livewire-select2 without Composer
On this page you can find all versions of the php package laspi94/livewire-select2. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download laspi94/livewire-select2
More information about laspi94/livewire-select2
Files in laspi94/livewire-select2
Package livewire-select2
Short Description Package for manipulate select2 input field dinamically with livewire.
License MIT
Informations about the package livewire-select2
LivewireSelect2
Package to integrate the select2 library with livewire, designed to reuse and encapsulate methods, and above all easy to implement in livewire components..
Requirements
- php8.2
- Select2: Have the select2 library installed aquí.
- Jquery: Have the Jquery library installed, select2 depends on it. aquí.
Setup
Call the directive package
Configuration
Example route.
Use
Import the LivewireSelect2 trait
In the mount method of the component, we will assign the properties that are associated with the field.
After the component starts, we will have to call the $this->loadSelect2() method, as we know, select2 needs the DOM already rendered to apply the properties and listeners in the document.
Inside our controller we also import our trait to access the select2PaginateList() method This is the one that will be responsible for returning our paginated items, the method assigned in our route should look something like this.
After that we must indicate in our model the columns that will be consulted in each call to AJAX, after adding the main columns, you can add more columns for which you want it to do the corresponding search within your model.
If you need to load a select2 that depends on another field, you can do it in the following way, passing the necessary parameter for the query and establishing the default value of our main field before calling "loadSelect2" again.
Now, with this same alias and just by manipulating the query you can easily reuse the query you want to perform, obtaining the paginated, preselected results without overloading the DOM.
HTML EXAMPLE
Validation
You can call the validator without any complications, within the livewire component
- If any rule exists, the error template indicated in our livewireSelect2.php "error_template" will be printed below the field.
The validation template will be generated within our wire:ignore, so to remove it, we can call the following method within our component.
Using by
Este proyecto es utilizado por las siguientes empresas:
- IDL S.A.