Skip to content

Commit

Permalink
Handle code submit for link via data attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Oksydan committed Sep 17, 2023
1 parent 6dc9ff1 commit 8d83e02
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ const codeLinkSubmitHandler = (event) => {
const link = event.currentTarget;
const input = document.querySelector('[name="discount_name"]');
const form = document.querySelector('.js-voucher-form');
const code = link.dataset?.code;

if (input && form) {
if (input && form && code) {
const formEvent = new Event('submit', {
bubbles: true,
cancelable: true,
});

input.value = link.textContent;
input.value = code;
form.dispatchEvent(formEvent);
}
};
Expand Down
5 changes: 4 additions & 1 deletion templates/checkout/_partials/cart-voucher.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@
{foreach from=$cart.discounts item=discount}
<li class="cart-summary-line">
<span class="label">
<a href="#" class="js-code font-weight-bold">{$discount.code}</a> - {$discount.name}
<a href="#" class="js-code font-weight-bold" data-code="{$discount.code}">
{$discount.code}
</a>
- {$discount.name}
</span>
</li>
{/foreach}
Expand Down

0 comments on commit 8d83e02

Please sign in to comment.