dialog to ask if remove item compltely
Some checks failed
CI / Check Style (push) Has been cancelled
CI / Run Clippy (push) Has been cancelled
CI / Run Tests (push) Has been cancelled

This commit is contained in:
Priec
2026-06-17 19:00:17 +02:00
parent 7be1726f1b
commit 7601fc704d
3 changed files with 13 additions and 2 deletions

View File

@@ -215,6 +215,7 @@ cart-empty = Your cart is empty.
cart-total = Total
cart-checkout = Proceed to checkout
cart-remove = Remove
cart-remove-confirm = Remove this item from the cart?
cart-update = Update
cart-continue = Continue shopping
checkout-title = Checkout

View File

@@ -215,6 +215,7 @@ cart-empty = Váš košík je prázdny.
cart-total = Spolu
cart-checkout = Pokračovať k pokladni
cart-remove = Odstrániť
cart-remove-confirm = Odstrániť túto položku z košíka?
cart-update = Aktualizovať
cart-continue = Pokračovať v nákupe
checkout-title = Pokladňa

View File

@@ -21,11 +21,20 @@
</td>
<td class="px-4 py-3 tabular-nums">{{ item.price }} {{ item.currency }}</td>
<td class="px-4 py-3">
{# Changing the quantity posts via htmx and swaps only #cart-body. #}
{# Changing the quantity posts via htmx (custom `cartchange` event) and
swaps only #cart-body. Dropping to 0 asks for confirmation first,
reverting to the previous quantity if the customer cancels. #}
<form method="post" action="/cart/update"
hx-post="/cart/update" hx-trigger="change" hx-target="#cart-body" hx-swap="innerHTML">
hx-post="/cart/update" hx-trigger="cartchange" hx-target="#cart-body" hx-swap="innerHTML">
<input type="hidden" name="product_id" value="{{ item.id }}">
<input type="number" name="quantity" min="0" max="{{ item.stock }}" value="{{ item.quantity }}"
@change="
if (parseInt($el.value || '0') <= 0 && !window.confirm('{{ t(key='cart-remove-confirm', lang=lang | default(value='sk')) }}')) {
$el.value = '{{ item.quantity }}';
} else {
$el.dispatchEvent(new Event('cartchange', { bubbles: true }));
}
"
class="w-20 rounded-radius border border-outline bg-surface px-2 py-1 text-sm text-on-surface focus:outline-2 focus:outline-primary dark:border-outline-dark dark:bg-surface-dark dark:text-on-surface-dark">
</form>
</td>