added peopulation of field values based on most recent entry

This commit is contained in:
Brian Bjarke Jensen
2025-12-03 19:45:03 +01:00
parent 2c4336a5e4
commit 95c2bf6744
+19
View File
@@ -336,6 +336,25 @@
lastDiaperChange.child_id; lastDiaperChange.child_id;
} }
} }
// Prepopulate poop and pee fields from most recent entry
try {
const response = await fetch("/api/diaper-changes", {
headers: { Authorization: `Bearer ${token}` },
});
if (response.ok) {
const changes = await response.json();
if (changes.length > 0) {
const last = changes[0];
document.getElementById("poopAmount").value = last.poop_amount || "";
document.getElementById("poopColor").value = last.poop_color || "";
document.getElementById("peeAmount").value = last.pee_amount || "";
document.getElementById("peeColor").value = last.pee_color || "";
}
}
} catch (error) {
// Ignore error, just use default
}
} }
} else { } else {
showMessage("Failed to load children", "error"); showMessage("Failed to load children", "error");