Files
elo-rezept-rechner/src/templates/nutrition.html
moerp 09a670727f
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
favicon
2024-01-30 15:50:39 +01:00

81 lines
3.3 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Neue Lebensmittel hinzufügen</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
<link rel="shortcut icon" href="../static/images/favicon.ico">
<script>
function updateSubmitButtonState() {
const inputs = document.querySelectorAll('#nutrition-form input');
const allFilled = Array.from(inputs).every(input => input.value.trim() !== '');
document.getElementById('submit-button').disabled = !allFilled;
}
function addNutritionEntry() {
const form = document.getElementById('nutrition-form');
const formData = new FormData(form);
fetch('/add_nutrition', {
method: 'POST',
body: formData
}).then(response => {
// Behandlung der Serverantwort
// Beispielsweise das Formular zurücksetzen
form.reset();
updateSubmitButtonState();
}).catch(error => {
console.error('Fehler:', error);
});
// ... Code, um den Eintrag zur Datenbank hinzuzufügen
// Nach dem Hinzufügen, setze alle Eingabefelder zurück
document.querySelectorAll('#nutrition-form input').forEach(input => {
input.value = ''; // Setzt den Wert jedes Eingabefeldes zurück
});
// Deaktiviere den "Hinzufügen"-Button wieder
document.getElementById('submit-button').disabled = true;
}
</script>
</head>
<body>
<nav id="navbar">
<h1>Elos Rezept Rechner</h1>
<ul>
<li><a href="/">Rechner</a></li>
<li><a href="/nutrition" class="active">Neue Lebensmittel</a></li>
</ul>
</nav>
<div class="content">
<form onsubmit="event.preventDefault(); addNutritionEntry();" method="POST" id="nutrition-form">
<table id="nutrition-input-table">
<tr>
<th>Lebensmittel</th>
<th>kcal</th>
<th>EW</th>
<th>Fett</th>
<th>KH</th>
<th>BST</th>
<th>CA</th>
</tr>
<tr>
<td><input type="text" name="food" placeholder="Lebensmittel" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="kcal" pattern="\d+(\.\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="ew" pattern="\d+(\.\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="fett" pattern="\d+(\.\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="kh" pattern="\d+(\.\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="bst" pattern="\d+(\.\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="ca" pattern="\d+(\.\d{1,2})?" placeholder="mg" oninput="updateSubmitButtonState()"></td>
</tr>
</table>
<button type="submit" id="submit-button" disabled>Hinzufügen</button>
</form>
</div>
</body>
</html>