@martinbean Thanks for advice. I've did it that way. Now what I'm facing is, that even if I set the target the all the button which are "created" by this extracted component disappear and only the one clicked has the spinner.
I want to achieve only to spin the clicked button.
To implement a global spinner for form submissions using Livewire and Bootstrap 5, you can create a reusable Livewire component that includes the spinner. This way, you can simply include this component in any form without having to repeatedly write the spinner code.
Here's how you can create a reusable Livewire component for a button with a loading spinner:
Create a Livewire Component:
First, create a new Livewire component. Let's call it loading-button.
php artisan make:livewire LoadingButton
Modify the Component View:
Edit the view of the loading-button component to include the button and the spinner. Here, we'll use Bootstrap 5 classes for the spinner.
wire:loading.remove hides the slot content (button label) when loading.
wire:loading shows the spinner and the "Loading..." text only during the loading state.
wire:loading.attr="disabled" disables the button while loading to prevent multiple submissions.
Use the Component in Forms:
You can now use this component in any form by wrapping the button label with the <livewire:loading-button> tag.
<form wire:submit.prevent="save">
<!-- Form fields here -->
<livewire:loading-button>
Save
</livewire:loading-button>
</form>
This approach encapsulates the loading logic within a single Livewire component, making it easy to reuse across different forms in your application. It also keeps your code DRY (Don't Repeat Yourself) and clean, as you avoid duplicating the spinner code in every form.