mysterious-toddler-20573
01/17/2023, 2:31 PMmysterious-toddler-20573
01/17/2023, 2:32 PMmysterious-toddler-20573
01/17/2023, 2:38 PMswapSpec = swapStyle swapOptions
swapStyle = "innerHTML" | ...
swapOptions = A bunch of stuff, I wrote the code stop being so judgy, I'm a people person can't you see that?!?
happy-pillow-29003
01/17/2023, 2:42 PM<input>
elements and a "add to cart" button on the form. I’d like to have -/+ buttons next to each article quantity (which wouldn’t be editable directly), and send a request to the server (which would be debounced to prevent sending a large number of requests if the user clicks on the button several times).
How would you go on implementing that?
I thought I would just add an hx-post
to each button, but I need to include in the request the id of the product that’s getting changed, along with the quantity (and update the quantity on screen).mysterious-toddler-20573
01/17/2023, 2:47 PMhtml
<button hx-post="/cart/items/1234212312321/increment">
Increment
</button>
happy-pillow-29003
01/17/2023, 2:54 PMhappy-pillow-29003
01/17/2023, 2:58 PMhx-post
attribute with the product id (eg. /basket/add/56) along with an hx-params="none"
so no parameter is sent with the request. Also add a hidden quantity input for the product
- Add an attribute hx-trigger="quantityChanged from:#qty_{{ product.id }}"
to the -/+ buttons
- In the JS code, add a listener on the -/+ buttons, debounce, and call htmx.trigger()
with a quantityChanged
event
- Still in the JS code, add a listener on htmx:configRequest
to add the quantity to the requestechoing-action-55459
01/17/2023, 4:01 PMdefaultSwapStyle
work here if its gonna pull the first item from the split argument? Is hx-swap="settle:1s"
valid? I'd expect it to use the default.
https://github.com/bigskysoftware/htmx/blob/4419bc4c90b087cfc23c04e54e45f5e071535022/src/htmx.js#L2375mysterious-toddler-20573
01/17/2023, 4:03 PMmysterious-toddler-20573
01/17/2023, 4:04 PMcareful-carpet-21555
01/17/2023, 4:15 PMmysterious-toddler-20573
01/17/2023, 4:42 PMlimited-teacher-83117
01/17/2023, 5:18 PMmethod=POST
for because the DX very nice, but PUT would be more semantic. Is there a straightfoward way to do this?tall-dinner-62086
01/17/2023, 5:22 PMhx-put
stocky-dentist-80693
01/17/2023, 5:22 PM<form hx-put="/save">
limited-teacher-83117
01/17/2023, 5:25 PMlimited-teacher-83117
01/17/2023, 5:27 PMhappy-knife-63802
01/17/2023, 7:18 PMhappy-knife-63802
01/17/2023, 7:18 PMmysterious-toddler-20573
01/17/2023, 8:09 PMmysterious-toddler-20573
01/17/2023, 8:51 PMmysterious-toddler-20573
01/17/2023, 10:59 PMadventurous-ocean-93733
01/17/2023, 11:01 PMhx-nudes
?mysterious-toddler-20573
01/17/2023, 11:01 PMmysterious-toddler-20573
01/17/2023, 11:01 PMmysterious-toddler-20573
01/17/2023, 11:02 PMadventurous-ocean-93733
01/17/2023, 11:02 PMmysterious-toddler-20573
01/17/2023, 11:02 PMorange-nail-40296
01/18/2023, 12:40 AMrefined-waiter-90422
01/18/2023, 5:21 AM