Fix discount fetch: trigger on any pre-filled value + debounced input
fetchDiscount now fires on page load if promo field has ANY value (not just from URL param), plus debounced on input events. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
e6150bcdce
commit
472e9f92dc
1 changed files with 6 additions and 4 deletions
|
|
@ -455,10 +455,12 @@ function fetchDiscount() {
|
|||
updateTotal();
|
||||
}).catch(function() { activeDiscount = null; updateTotal(); });
|
||||
}
|
||||
// Fetch on load if promo pre-filled
|
||||
if (promoFromUrl) { setTimeout(fetchDiscount, 500); }
|
||||
// Fetch on blur of promo field
|
||||
document.getElementById("pw-promo").addEventListener("blur", fetchDiscount);
|
||||
// Fetch on load if promo field has any value
|
||||
var promoField = document.getElementById("pw-promo");
|
||||
if (promoField.value.trim()) { setTimeout(fetchDiscount, 300); }
|
||||
// Fetch on blur and input of promo field
|
||||
promoField.addEventListener("blur", fetchDiscount);
|
||||
promoField.addEventListener("input", function() { clearTimeout(promoField._debounce); promoField._debounce = setTimeout(fetchDiscount, 600); });
|
||||
|
||||
function updateTotal() {
|
||||
var selected = [];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue