Fix 'btn is not defined' JS error in Record meal modal
Build and Deploy / build-and-deploy (push) Successful in 12m59s
Build and Deploy / build-and-deploy (push) Successful in 12m59s
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
This commit is contained in:
+4
-1
@@ -654,9 +654,11 @@ cookLogJs =
|
|||||||
, "var dateInput = document.getElementById('roux-record-date');"
|
, "var dateInput = document.getElementById('roux-record-date');"
|
||||||
, "var commentInput = document.getElementById('roux-record-comment');"
|
, "var commentInput = document.getElementById('roux-record-comment');"
|
||||||
, "var errorEl = document.getElementById('roux-record-error');"
|
, "var errorEl = document.getElementById('roux-record-error');"
|
||||||
|
, "var activeBtn = null;"
|
||||||
, "if (!btns.length || !modal || !form) return;"
|
, "if (!btns.length || !modal || !form) return;"
|
||||||
, ""
|
, ""
|
||||||
, "function showModal() {"
|
, "function showModal() {"
|
||||||
|
, " activeBtn = this;"
|
||||||
, " dateInput.value = new Date().toISOString().slice(0,10);"
|
, " dateInput.value = new Date().toISOString().slice(0,10);"
|
||||||
, " commentInput.value = '';"
|
, " commentInput.value = '';"
|
||||||
, " errorEl.style.display = 'none';"
|
, " errorEl.style.display = 'none';"
|
||||||
@@ -680,7 +682,8 @@ cookLogJs =
|
|||||||
, " e.preventDefault();"
|
, " e.preventDefault();"
|
||||||
, " var date = dateInput.value;"
|
, " var date = dateInput.value;"
|
||||||
, " var comment = commentInput.value;"
|
, " var comment = commentInput.value;"
|
||||||
, " var filename = btn.dataset.filename;"
|
, " if (!activeBtn) return;"
|
||||||
|
, " var filename = activeBtn.dataset.filename;"
|
||||||
, " var body = 'cooked-date=' + encodeURIComponent(date);"
|
, " var body = 'cooked-date=' + encodeURIComponent(date);"
|
||||||
, " if (comment) body += '&comment=' + encodeURIComponent(comment);"
|
, " if (comment) body += '&comment=' + encodeURIComponent(comment);"
|
||||||
, " var res = await fetch('/cook-log/' + encodeURIComponent(filename), {"
|
, " var res = await fetch('/cook-log/' + encodeURIComponent(filename), {"
|
||||||
|
|||||||
Reference in New Issue
Block a user