Ajoute un sélecteur de date/heure sur les entrées

flatpickr 4.6.13 (fr, 24 h), embarqué dans le binaire, sur les champs
datetime-local, y compris ceux chargés par htmx. La valeur envoyée au
serveur reste au format YYYY-MM-DDTHH:MM ; couleurs reprises du thème.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Romulus21andClaude Opus 5.5 committed 2026-10-26 15:49:07 +01:00
1 parent 7c22567b07
commit 092bc2fb3e
8 files changed
+97 -1

No files matched your search

+30
View File
@@ -31,3 +31,33 @@ document.addEventListener("submit", (event) => {
const message = event.target.dataset.confirm;
if (message && !confirm(message)) event.preventDefault();
});
// Date/time pickers on entry fields, including rows swapped in by htmx.
// The original input keeps the `YYYY-MM-DDTHH:MM` value sent to the server.
htmx.onLoad((root) => {
for (const input of root.querySelectorAll('input[type="datetime-local"]')) {
flatpickr(input, {
locale: "fr",
enableTime: true,
time_24hr: true,
dateFormat: "Y-m-d\\TH:i",
altInput: true,
altFormat: "d/m/Y H:i",
allowInput: true,
onReady: (_dates, _str, fp) =>
fp.altInput.setAttribute("aria-label", input.getAttribute("aria-label")),
});
}
});
// The calendars live in <body>: drop them with the inputs htmx removes.
document.body.addEventListener("htmx:beforeCleanupElement", (event) => {
event.target._flatpickr?.destroy();
});
// Removes a row without a request (e.g. cancelling a duplicate).
function removeRow(button) {
const row = button.closest("tr");
for (const input of row.querySelectorAll("input")) input._flatpickr?.destroy();
row.remove();
}