This commit is contained in:
parent
c9d50b6018
commit
79cf147345
@ -32,6 +32,24 @@
|
||||
});
|
||||
});
|
||||
|
||||
function recalculateTableBasedOnPortions() {
|
||||
const portions = parseInt(document.getElementById('portions').value, 10) || 1;
|
||||
const table = document.getElementById('nutrition-table');
|
||||
Array.from(table.rows).slice(1).forEach(row => {
|
||||
const weightCell = row.cells[1];
|
||||
const originalWeight = parseInt(weightCell.getAttribute('data-original-weight'), 10) || parseInt(weightCell.innerText, 10);
|
||||
const newWeight = Math.ceil(originalWeight / portions);
|
||||
weightCell.innerText = newWeight;
|
||||
// Optional: Speichern des ursprünglichen Gewichts, falls noch nicht geschehen
|
||||
if (!weightCell.hasAttribute('data-original-weight')) {
|
||||
weightCell.setAttribute('data-original-weight', originalWeight.toString());
|
||||
}
|
||||
});
|
||||
// Trigger die Neuberechnung der Gesamtnährwerte
|
||||
updateTotalNutrition();
|
||||
}
|
||||
|
||||
|
||||
function restoreTableFromLocalStorage() {
|
||||
let entries = JSON.parse(localStorage.getItem('nutritionEntries')) || [];
|
||||
let oneHourAgo = new Date().getTime() - (60 * 60 * 1000);
|
||||
@ -194,6 +212,7 @@ function updateTotalNutrition() {
|
||||
|
||||
<div class="content">
|
||||
<form onsubmit="event.preventDefault(); addProduct();" id="product-form">
|
||||
<input type="number" id="portions" name="portions" placeholder="Portionen" min="1" value="1" oninput="recalculateTableBasedOnPortions()">
|
||||
<label for="my_combobox">Wählen Sie ein Lebensmittel</label>
|
||||
<input list="products" name="my_combobox" id="my_combobox" placeholder="Lebensmittel" oninput="updateButtonState()" autocomplete="off">
|
||||
<datalist id="products">
|
||||
@ -202,7 +221,7 @@ function updateTotalNutrition() {
|
||||
<input type="number" id="weight" name="weight" placeholder="Gramm" oninput="updateButtonState()">
|
||||
<button type="submit" id="submit-button" disabled>Hinzufügen</button>
|
||||
|
||||
<input type="number" id="portions" name="portions" placeholder="Portionen" min="1" value="1">
|
||||
|
||||
|
||||
|
||||
</form>
|
||||
|
Loading…
x
Reference in New Issue
Block a user