Hey!
I have a cart with cart items. Each item has a quantity input box. And next to it a [-] and [+] button to increase / decrease with 1.
<button wire:click.prevent="$set('quantity', {{ $quantity - 1 }})"> -</button>
<input wire:model="quantity" type="number">
<button wire:click.prevent="$set('quantity', {{ $quantity + 1 }})"> +</button>
All works fine.
The thing is, the + and - buttons feel a bit clunky, because you have to wait for the xhr roundtrip for the quantity in the input box to update.
I’ve looked at javascript integration, and found this $wire.increment()
here https://laravel-livewire.com/docs/2.x/alpine-js
, but that also runs on the server, so the issue stays, if I understand correctly.
- Is there a “livewire way” to set the quantity in the input box before the xhr roundtrip?
- Is there a way to do this with another component on the page? (E.g. a cart totals counter in the header)
Kind Regards,
John