diff --git a/scripts/main.js b/scripts/main.js index fc66939..591eeb8 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -27,32 +27,35 @@ async function loadProducts() { barcodeForm.addEventListener("submit", (e) => { e.preventDefault(); + + if (to_fill_product_index < 5) { - const barcode = document.getElementById('barcode_input').value - var chosen_product - for (index = 0; index < all_products.length; index++) { - if (all_products[index].barcode == barcode) { - chosen_product = all_products[index] + const barcode = document.getElementById('barcode_input').value + var chosen_product + for (index = 0; index < all_products.length; index++) { + if (all_products[index].barcode == barcode) { + chosen_product = all_products[index] + } } + + barcode_input.value = "" + + const product_placeholders = document.getElementsByClassName('product_col') + const chosen_product_placeholder = product_placeholders[to_fill_product_index] + const image_product = chosen_product_placeholder.getElementsByClassName('product_image')[0] + const price_product = chosen_product_placeholder.getElementsByClassName('product_price')[0] + const total_price_holder = document.getElementById("totalprice") + + total_price += chosen_product.price + + image_product.setAttribute('src', api_url + "/icons/" + chosen_product.image_filename); + price_product.textContent = "\u20AC " + chosen_product.price + total_price_holder.textContent = "\u20AC " + total_price + + to_fill_product_index += 1 + }else{ + barcode_input.value = "" } - - barcode_input.value = "" - - const product_placeholders = document.getElementsByClassName('product_col') - const chosen_product_placeholder = product_placeholders[to_fill_product_index] - const image_product = chosen_product_placeholder.getElementsByClassName('product_image')[0] - const price_product = chosen_product_placeholder.getElementsByClassName('product_price')[0] - const total_price_holder = document.getElementById("totalprice") - - total_price += chosen_product.price - - console.log(image_product) - - image_product.setAttribute('src', api_url + "/icons/" + chosen_product.image_filename); - price_product.textContent = "\u20AC " + chosen_product.price - total_price_holder.textContent = "\u20AC " + total_price - - to_fill_product_index += 1 }); }