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
+47 -15
View File
@@ -235,7 +235,7 @@
<button
type="button"
class="button secondary"
onclick="window.location.href='/diapers.html'"
onclick="window.location.href=getReturnUrl()"
>
Cancel
</button>
@@ -249,6 +249,16 @@
window.location.href = "/login.html";
}
// Determine return URL based on referrer
function getReturnUrl() {
const referrer = document.referrer;
if (referrer.includes('/diapers.html')) {
return '/diapers.html';
}
// Default to home page
return '/';
}
// Check if we're in edit mode
const urlParams = new URLSearchParams(window.location.search);
const diaperChangeId = urlParams.get("id");
@@ -277,12 +287,32 @@
children = await response.json();
const select = document.getElementById("childSelect");
children.forEach((child) => {
const option = document.createElement("option");
option.value = child.id;
option.textContent = child.name;
select.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 = select.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="childSelect" name="childSelect" value="${child.id}" />
`;
} else {
// Multiple children: show dropdown (clear the placeholder first)
select.innerHTML = '';
children.forEach((child) => {
const option = document.createElement("option");
option.value = child.id;
option.textContent = child.name;
select.appendChild(option);
});
}
// If editing, load the diaper change data
if (isEditMode) {
@@ -295,14 +325,16 @@
.toISOString()
.slice(0, 16);
// Load last used child from localStorage
const lastDiaperChange = JSON.parse(
localStorage.getItem("lastDiaperChange") || "{}",
);
// Load last used child from localStorage (only for multiple children)
if (children.length > 1) {
const lastDiaperChange = JSON.parse(
localStorage.getItem("lastDiaperChange") || "{}",
);
if (lastDiaperChange.child_id) {
document.getElementById("childSelect").value =
lastDiaperChange.child_id;
if (lastDiaperChange.child_id) {
document.getElementById("childSelect").value =
lastDiaperChange.child_id;
}
}
}
} else {
@@ -431,7 +463,7 @@
"success",
);
setTimeout(() => {
window.location.href = "/diapers.html";
window.location.href = getReturnUrl();
}, 1000);
} else {
const errorData = await response.json();