fix: capture accessnumber in local variable for PDF fetch - Prevents null value in async PDF generation URL after val2

This commit is contained in:
mahdahar 2026-02-12 13:09:30 +07:00
parent 9e374103fa
commit 7b6d7f6d85

View File

@ -210,10 +210,12 @@ document.addEventListener('alpine:init', () => {
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ userid: `${userid}` }) body: JSON.stringify({ userid: `${userid}` })
}).then(response => response.json()).then(data => { }).then(response => response.json()).then(data => {
// Capture accessnumber before async operations
const currentAccessnumber = accessnumber;
if (data.val === 2) { if (data.val === 2) {
this.showToast(`Validated (val2): ${accessnumber} - PDF queued`); this.showToast(`Validated (val2): ${currentAccessnumber} - PDF queued`);
// Trigger PDF auto-generation after val2 // Trigger PDF auto-generation after val2
fetch(`${BASEURL}/report/${accessnumber}/pdf`).then(res => res.json()).then(pdfData => { fetch(`${BASEURL}/report/${currentAccessnumber}/pdf`).then(res => res.json()).then(pdfData => {
if (pdfData.success) { if (pdfData.success) {
console.log('PDF generation queued:', pdfData.jobId); console.log('PDF generation queued:', pdfData.jobId);
} else { } else {