Compare commits

...

8 Commits

Author SHA1 Message Date
Richard Schreiber
2c5e59b557 fix previousValue calc 2023-06-03 06:52:15 +02:00
Richard Schreiber
73997529c1 Remove from variants 2023-06-03 06:51:59 +02:00
Richard Schreiber
647190368c improve naming 2023-06-02 09:22:24 +02:00
Richard Schreiber
e1e9c94576 remove from add_on step as too complex there 2023-06-02 09:19:53 +02:00
Richard Schreiber
73d2077d67 respect existing items in cart for order_min 2023-06-02 09:14:03 +02:00
Richard Schreiber
956ee2785f refine onchange handling 2023-06-02 09:12:34 +02:00
Richard Schreiber
1b4be10b33 force item-order-min on blur if quantity not 0 2023-06-01 16:19:12 +02:00
Richard Schreiber
883b5e3c1c Presale: respect order-min-quantity 2023-06-01 16:15:14 +02:00
4 changed files with 21 additions and 2 deletions

View File

@@ -21,7 +21,7 @@
</div>
<div role="rowgroup" class="firstchild-in-panel">
{% for line in cart.positions %}
<div role="row" class="row cart-row {% if hide_prices %}hide-prices{% endif %} {% if download %}has-downloads{% endif %}{% if editable %}editable{% endif %}">
<div role="row" class="row cart-row {% if hide_prices %}hide-prices{% endif %} {% if download %}has-downloads{% endif %}{% if editable %}editable{% endif %}" data-item="{{ line.item.id }}" data-count="{{ line.count }}">
<div role="cell" class="product">
<p>
{% if line.addon_to %}

View File

@@ -344,6 +344,7 @@
<button type="button" data-step="-1" data-controls="item_{{ item.id }}" class="btn btn-default input-item-count-dec" aria-label="{% trans "Decrease quantity" %}"
{% if not ev.presale_is_running %}disabled{% endif %}>-</button>
<input type="number" class="form-control input-item-count" placeholder="0" min="0"
{% if item.min_per_order and item.min_per_order > 1 %}data-min="{{ item.min_per_order }}"{% endif %}
{% if not ev.presale_is_running %}disabled{% endif %}
{% if itemnum == 1 %}value="1"{% endif %}
{% if item.free_price %}

View File

@@ -257,6 +257,7 @@
<div class="input-item-count-group">
<button type="button" data-step="-1" data-controls="variation_{{ item.id }}_{{ var.id }}" class="btn btn-default input-item-count-dec" aria-label="{% trans "Decrease quantity" %}">-</button>
<input type="number" class="form-control input-item-count" placeholder="0" min="0"
{% if item.min_per_order and item.min_per_order > 1 %}data-min="{{ item.min_per_order }}"{% endif %}
max="{{ var.order_max }}"
id="variation_{{ item.id }}_{{ var.id }}"
name="variation_{{ item.id }}_{{ var.id }}"
@@ -400,6 +401,7 @@
<button type="button" data-step="-1" data-controls="item_{{ item.id }}" class="btn btn-default input-item-count-dec" aria-label="{% trans "Decrease quantity" %}">-</button>
<input type="number" class="form-control input-item-count"
placeholder="0" min="0"
{% if item.min_per_order and item.min_per_order > 1 %}data-min="{{ item.min_per_order }}"{% endif %}
max="{{ item.order_max }}"
id="item_{{ item.id }}"
name="item_{{ item.id }}"

View File

@@ -121,10 +121,26 @@ var form_handlers = function (el) {
e.preventDefault();
var step = parseFloat(this.getAttribute("data-step"));
var controls = document.getElementById(this.getAttribute("data-controls"));
var currentValue = parseFloat(controls.value);
var currentValue = parseFloat(controls.value) || 0;
controls.value = Math.max(controls.min, Math.min(controls.max || Number.MAX_SAFE_INTEGER, (currentValue || 0) + step));
controls.dispatchEvent(new Event("change"));
});
el.find("input[data-min]").each(function(i) {
this.previousValue = parseFloat(this.value) || 0;
}).on("change", function(e) {
var currentValue = parseFloat(this.value) || 0;
var itemOrderMin = parseFloat(this.getAttribute("data-min")) || 0;
if (itemOrderMin) {
document.querySelectorAll(".cart-row[data-item='"+this.id.substring(5)+"']").forEach(function(row) {
itemOrderMin -= (parseFloat(row.getAttribute("data-count")) || 1)
});
if (itemOrderMin < 0) itemOrderMin = 0;
}
if (currentValue && currentValue < itemOrderMin) {
this.value = this.previousValue > currentValue ? 0 : itemOrderMin;
}
this.previousValue = this.value;
});
el.find("script[data-replace-with-qr]").each(function () {
var $div = $("<div>");