How to use Fluxui Select and autocomplete with remote data? #800
-
How to use select and autocomplete with remote data like this |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
@ramabie You can use input and generate dynamic options by the search https://fluxui.dev/components/select#dynamic-options |
Beta Was this translation helpful? Give feedback.
-
What I mean is ScreenRecording_12-04-2024.08-17-08_1.mp4` new TomSelect('#select-repo',{
|
Beta Was this translation helpful? Give feedback.
-
I usually do it like this, but when using flux ui, I still don't know how to implement it This is an example of a script snippet |
Beta Was this translation helpful? Give feedback.
-
namespace App\Livewire\Service;
use App\Livewire\Forms\ServiceForm;
use App\Models\Customer;
use Livewire\Component;
class ServiceCreate extends Component
{
public ServiceForm $form;
public $modalServiceCreate = false;
public function getCustomer($name)
{
return collect(Customer::select('id', 'name')->where('name', 'like', '%'.$name.'%')->get());
}
public function render()
{
return view('livewire.service.service-create');
}
} // component Tom
@props(['disabled' => false])
<div wire:ignore>
<select {{ $disabled ? 'disabled' : '' }} {!! $attributes->merge(['class' => 'border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm']) !!}>
{{ $slot }}
</select>
</div>
// livewire.service.service-create
<div class="col-span-12" x-id="['text-input']">
<x-label ::for="$id('text-input')" value="Customer" />
<x-tom
x-init="$el.customer = new Tom($el, {
sortField: {
field: 'name',
direction: 'asc'
},
valueField: 'id',
labelField: 'name',
searchField: 'name',
load: function(query, callback) {
$wire.getCustomer(query).then(results => {
callback(results);
}).catch(() => {
callback();
})
},
render: {
option: function (item, escape) {
return `<div>${escape(item.name)}</div>`
},
item: function (item, escape) {
return `<div>${escape(item.name)}</div>`
}
}
});"
wire:model="form.customer"
::id="$id('text-input')" class="mt-1 w-full" require>
<option></option>
</x-tom>
<x-input-error for="form.customer" class="mt-1" />
</div>
|
Beta Was this translation helpful? Give feedback.
@ramabie you'd do it like this