final version, submitted to teacher

This commit is contained in:
2024-12-24 17:34:52 +01:00
parent c0528a2488
commit 46a42c99c2
16 changed files with 394 additions and 105 deletions

View File

@@ -0,0 +1,29 @@
let productCount = document.querySelectorAll('.product-item').length;
function addProduct() {
const container = document.getElementById('product-container');
const newProduct = document.createElement('div');
newProduct.classList.add('product-item');
newProduct.id = `product-item-${productCount}`;
newProduct.innerHTML = `
<label for="product_${productCount}">Produkt:</label>
<select id="product_${productCount}" name="products[${productCount}][id]" required>
<option value="" disabled selected>Vyberte produkt</option>
{% for product in products %}
<option value="{{ product['ID_Produktu'] }}">{{ product['Nazev'] }}</option>
{% endfor %}
</select>
<label for="quantity_${productCount}">Množství:</label>
<input type="number" id="quantity_${productCount}" name="products[${productCount}][quantity]" value="0" min="0" required>
<button type="button" onclick="removeProduct(${productCount})">Odstranit</button>
`;
container.appendChild(newProduct);
productCount++;
}
function removeProduct(index) {
const productItem = document.getElementById(`product-item-${index}`);
if (productItem) {
productItem.remove();
}
}