This topic is locked

SweetAlert Dialog not submitting to server

2/3/2024 11:16:35 AM
PHPRunner General questions
B
Bob D authorDevClub member

I have a SweetAlert dialog that request four dates from the user. For some reason it is not submitting to the server. The data does show up in the console.log(). The following is my code in the Before Event. What am I missing?

Swal.fire({
title: 'Update Device Dates',
html: `
<div>
<label for="swal-input1">Original Start Year:</label>
<input id="swal-input1" type="date" class="swal2-input">
</div>
<div>
<label for="swal-input2">Original End Year:</label>
<input id="swal-input2" type="date" class="swal2-input" onchange="document.getElementById('swal-input3').value = this.value">
</div>
<div>
<label for="swal-input3">Upgrade Start Year:</label>
<input id="swal-input3" type="date" class="swal2-input">
</div>
<div>
<label for="swal-input4">Upgrade End Year:</label>
<input id="swal-input4" type="date" class="swal2-input">
</div>
`,
width: '450px',
preConfirm: () => {
// Collect the values into a params object
const data = {
originalStartYear: document.getElementById('swal-input1').value,
originalEndYear: document.getElementById('swal-input2').value,
upgradeStartYear: document.getElementById('swal-input3').value,
upgradeEndYear: document.getElementById('swal-input4').value
};
// You can validate the params here if needed
return data;
}
}).then((result) => {
if (result.isConfirmed && result.value) {
const data = result.value;
params = data;
submit();
console.log('Submitted Parameters:', params);
}
});

// Function to set the upgradeStartYear equal to the originalEndYear
const originalEndYearInput = Swal.getContent().querySelector('#swal-input2');
const upgradeStartYearInput = Swal.getContent().querySelector('#swal-input3');

originalEndYearInput.addEventListener('change', () => {
upgradeStartYearInput.value = originalEndYearInput.value;
});

return false;