mirror of
https://framagit.org/la-chariotte/la-chariotte.git
synced 2025-05-02 20:01:51 +02:00
167 retours Alexis
This commit is contained in:
parent
7a371d1b18
commit
c952b49920
1 changed files with 6 additions and 4 deletions
|
@ -185,13 +185,15 @@
|
|||
{% block extra_js %}
|
||||
// Compute total price whenever a value in input is modified
|
||||
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
|
||||
total_price = 0;
|
||||
inputs = [...document.getElementsByTagName("input")].filter(input => input.getAttribute("name").indexOf("quantity_") === 0); //filter the inputs to get the quantity inputs only
|
||||
|
||||
prices = {{ prices_dict | safe }};
|
||||
let total_price = 0;
|
||||
|
||||
for (let input of inputs) {
|
||||
input_name = input.getAttribute("name");
|
||||
item_id = input_name.split("_")[1];
|
||||
prices = {{ prices_dict | safe }};
|
||||
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
|
||||
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
|
||||
}
|
||||
|
||||
[].forEach.call(document.getElementsByClassName('total'), function (el) {
|
||||
|
|
Loading…
Reference in a new issue