changed dropdown to read-only textfield when only 1 associated child and fixed redirects after manual entries
Build and Push Docker Image / build-and-push (pull_request) Successful in 58s
Python Code Quality / python-code-quality (pull_request) Successful in 10s
Python Test / python-test (pull_request) Successful in 18s

This commit is contained in:
Brian Bjarke Jensen
2025-11-12 16:39:16 +01:00
parent 9d1ca55905
commit 28a5df4f12
7 changed files with 294 additions and 95 deletions
+39 -10
View File
@@ -196,6 +196,16 @@
window.location.href = "/login.html";
}
// Determine return URL based on referrer
function getReturnUrl() {
const referrer = document.referrer;
if (referrer.includes('/sleep.html')) {
return '/sleep.html';
}
// Default to home page
return '/';
}
const form = document.getElementById("logSleepForm");
const messageDiv = document.getElementById("message");
const submitBtn = document.getElementById("submitBtn");
@@ -249,13 +259,32 @@
return;
}
// Populate select dropdown
children.forEach((child) => {
const option = document.createElement("option");
option.value = child.id;
option.textContent = child.name;
childSelect.appendChild(option);
});
// Populate select dropdown or show single child
if (children.length === 1) {
// Single child: replace dropdown with text display
const child = children[0];
const formGroup = childSelect.parentElement;
formGroup.innerHTML = `
<label for="childName">Child</label>
<input
type="text"
id="childName"
value="${child.name}"
readonly
style="background-color: #f5f5f5; cursor: default;"
/>
<input type="hidden" id="childId" name="childId" value="${child.id}" />
`;
} else {
// Multiple children: show dropdown (clear placeholder first)
childSelect.innerHTML = '';
children.forEach((child) => {
const option = document.createElement("option");
option.value = child.id;
option.textContent = child.name;
childSelect.appendChild(option);
});
}
// Show form, hide loading
loadingDiv.style.display = "none";
@@ -353,9 +382,9 @@
: "Sleep logged successfully!",
"success",
);
// Redirect to sleep page after 1 second
// Redirect to appropriate page after 1 second
setTimeout(() => {
window.location.href = "/sleep.html";
window.location.href = getReturnUrl();
}, 1000);
} else {
showMessage(
@@ -378,7 +407,7 @@
}
function goBack() {
window.location.href = "/sleep.html";
window.location.href = getReturnUrl();
}
</script>
</body>