Support empty ?a= for custom entry, improve validation message

This commit is contained in:
Ian Gulliver
2026-01-17 18:04:56 -07:00
parent 107fd2d25f
commit 2b4d64df15

View File

@@ -151,14 +151,16 @@
const amountParam = params.get('a'); const amountParam = params.get('a');
let selectedDonation = 10; let selectedDonation = 10;
if (amountParam) { if (amountParam !== null) {
const amount = parseFloat(amountParam);
if (amount > 0) {
document.getElementById('custom-amount').value = amount % 1 === 0 ? amount : amount.toFixed(2);
const group = document.getElementById('donation-group'); const group = document.getElementById('donation-group');
group.querySelectorAll('wa-button').forEach(b => b.classList.remove('selected')); group.querySelectorAll('wa-button').forEach(b => b.classList.remove('selected'));
group.querySelector('wa-button[data-value="custom"]').classList.add('selected'); group.querySelector('wa-button[data-value="custom"]').classList.add('selected');
selectedDonation = 'custom'; selectedDonation = 'custom';
const amount = parseFloat(amountParam);
if (amount > 0) {
document.getElementById('custom-amount').value = amount % 1 === 0 ? amount : amount.toFixed(2);
} else {
document.getElementById('custom-amount').value = '';
} }
} }
@@ -195,7 +197,7 @@
} }
if (donationCents <= 0) { if (donationCents <= 0) {
alert('Please select a donation amount'); alert(selectedDonation === 'custom' ? 'Please enter a donation amount' : 'Please select a donation amount');
return; return;
} }