Form Select Loading indicator while filling from API
Hi. I select an user, and fill a select button whit the prices available to that user from an API.
Is there a way to show a "loading" indicator while the Select is being filled?
25 Replies
Where would you like to show the loading indicator?
Anywhere... maybe next to the select...
Solution
maybe in a hint?
Great!
if you want to use a loading indicator
wire:loading is the key (Y) thanks!
how to get the wire:target or rather see the contents data variable? When I add wire:target on my select, it doesn't show.
share your code
why would you like to show a loading?
Coz the appointment service is a third party api call
you haven't set a target
coz setting wire:target='data.appointment_time' doesn't show the loader
ahh, in the options, sorry... wire:loading will work if you have a livewire request, I think
if you are using
live()
, for exampleOh. Let me try using
->live()
Nope. Even after using live, it won't work.if you would target property with live it should maybe work. https://livewire.laravel.com/docs/wire-loading#targeting-property-updates
i tried wire:target="data.appointment_time" and wire:target="appointment_time" both didn't work
I too have gone through this, but somehow don't know why it's not working in filament form.
maybe because it's too fast?
this one works for me
if i remove wire:target, even on create button click it shows loading, which is not desirable
No, tried throttling for 5 secs.
is appointment_date live?
share the whole code..
Forms\Components\DatePicker::make('appointment_date')
->minDate(today())
->native(false)
->format('Y-m-d')
->closeOnDateSelection()
// ->after(now())
->live()
->required(),
Forms\Components\Select::make('appointment_time')
->native(false)
->live()
->hint(new HtmlString(Blade::render('<div wire:loading wire:target="data.appointment_time">Loading... </div>
<x-filament::loading-indicator class="h-5 w-5" wire:loading />')))
->options(function (Get $get) {
if (empty($get('appointment_date'))) {
return [];
} else {
return (new AppointmentService())->getAvailableTimesForDate($get('appointment_date'));
}
})
// ->hidden(fn (Get $get) => !$get('appointment_date'))
->rules([
fn (Get $get): Closure => function (string $attribute, string $value, Closure $fail) use ($get) {
$appointments = (new AppointmentService())->getAvailableTimesForDate($get('appointment_date'));
if (!array_key_exists($value, $appointments)) {
$fail('Sorry, the time slot is not available. Please pick another time slot.');
}
},
])
->required(),
Yes. it's live
try this code and check if it works
If i put the sleep there, the create dialog takes 1 second to open. I put sleep(10) the create dialog took 10seconds to open 😃
Trying in resource
Same thing, the create page opens after 1/5 seconds.