167 retours Alexis

This commit is contained in:
Bastien Roy 2024-02-04 11:32:12 +01:00 committed by Laetitia Getti
parent 7a371d1b18
commit c952b49920

View file

@ -185,13 +185,15 @@
{% block extra_js %} {% block extra_js %}
// Compute total price whenever a value in input is modified // Compute total price whenever a value in input is modified
document.getElementById("inputs-parent").addEventListener("change", function () { document.getElementById("inputs-parent").addEventListener("change", function () {
var inputs = [...document.getElementsByTagName("input")].filter(input => input.getAttribute("name").indexOf("quantity_") === 0); //filter the inputs to get the quantity inputs only inputs = [...document.getElementsByTagName("input")].filter(input => input.getAttribute("name").indexOf("quantity_") === 0); //filter the inputs to get the quantity inputs only
total_price = 0;
prices = {{ prices_dict | safe }};
let total_price = 0;
for (let input of inputs) { for (let input of inputs) {
input_name = input.getAttribute("name"); input_name = input.getAttribute("name");
item_id = input_name.split("_")[1]; item_id = input_name.split("_")[1];
prices = {{ prices_dict | safe }}; total_price = Number((total_price + (prices[item_id] * input.value)).toFixed(2)); //Limit precision to 2 digits for each added part and for the total
total_price = Number((total_price + Number((prices[item_id] * input.value).toFixed(2))).toFixed(2)); //Limit precision to 2 digits for each added part and for the total
} }
[].forEach.call(document.getElementsByClassName('total'), function (el) { [].forEach.call(document.getElementsByClassName('total'), function (el) {