From 7b64f9576bf0496e923c18cfe1129db83663a001 Mon Sep 17 00:00:00 2001 From: James Brechtel Date: Tue, 26 May 2026 07:44:50 -0400 Subject: [PATCH] Fix 'btn is not defined' JS error in Record meal modal When the trigger JS was updated to use querySelectorAll('.roux-record-trigger') for dual-button support, the variable was renamed from 'btn' to 'btns' but the submit handler still referenced 'btn'. This commit: - Adds activeBtn tracking: the button that opened the modal is stored in activeBtn via 'this' in the click handler - Uses activeBtn.dataset.filename in the submit handler (with null guard) - Removes the stale btn reference --- src/Roux/Html.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Roux/Html.hs b/src/Roux/Html.hs index 87657ae..62d2229 100644 --- a/src/Roux/Html.hs +++ b/src/Roux/Html.hs @@ -654,9 +654,11 @@ cookLogJs = , "var dateInput = document.getElementById('roux-record-date');" , "var commentInput = document.getElementById('roux-record-comment');" , "var errorEl = document.getElementById('roux-record-error');" + , "var activeBtn = null;" , "if (!btns.length || !modal || !form) return;" , "" , "function showModal() {" + , " activeBtn = this;" , " dateInput.value = new Date().toISOString().slice(0,10);" , " commentInput.value = '';" , " errorEl.style.display = 'none';" @@ -680,7 +682,8 @@ cookLogJs = , " e.preventDefault();" , " var date = dateInput.value;" , " var comment = commentInput.value;" - , " var filename = btn.dataset.filename;" + , " if (!activeBtn) return;" + , " var filename = activeBtn.dataset.filename;" , " var body = 'cooked-date=' + encodeURIComponent(date);" , " if (comment) body += '&comment=' + encodeURIComponent(comment);" , " var res = await fetch('/cook-log/' + encodeURIComponent(filename), {"