livewire: wire:loading not working when wire:click is added to button
Description
wire:loading not working when wire:click is added to button
Steps to reproduce
This is my button with two icons, one on loading state and cart icon on normal state:
<button class="w-full md:w-auto md:float-right bg-green-500 hover:bg-green-600 py-2 px-4 rounded-full text-white font-semibold text-lg focus:outline-none" wire:click="placeOrder" wire:loading.class="opacity-50 cursor-not-allowed" wire:loading.attr="disabled">
<i class="icon-cart" wire:loading.remove></i>
<i class="icon-spin5 animate-spin" wire:loading></i>
Place Order
</button>
Cart icon gets removed and loading icon shows, but wire:loading.class="opacity-50 cursor-not-allowed" and wire:loading.attr="disabled" doesn’t work at all.
If i remove wire:click="placeOrder" from button it works fine.
Context
- Livewire version: v1.0.14, v1.1.0
- Laravel version: 7.0
- Browser: Chrome, Safari
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (2 by maintainers)
@calebporzio @jeffochoa Just wanted to note I came across the same issue. This works:
This does not:
But with some further investigation, it seems like it was a problem with targeting the DOM. Adding some unique id attributes to the buttons fixed it:
Hope that might get closer to the issue.
As a workaround to this problem, I have set the
wire:targetattribute to both of the relevant actions.In @flamisz example, this would mean adding
wire:target="cancel, submit"to the cancel button (assuming thesubmitbutton triggers an action calledsubmit)For anyone else coming across this problem later, https://github.com/livewire/livewire/issues/1012#issuecomment-687573922 is a possible work around.
I used this to resolve an issue where I was replacing one button with another button, and the second button was becoming disabled.
@calebporzio I have the same issue with a
<li>:<li wire:loading.class="opacity-50" x-on:click="open = false" wire:click="$set('category_name', '{{ $category->name }}')" class="transition-colors cursor-pointer hover:bg-gray-100 pt-3 px-4 text-sm">If I delete wire:click event, wire:loading.class runs.
That does the trick, thanks @acurrieclark . But I still believe it’s a bug that should be solved.