Update quantity from external JS

Created on 10 December 2020, almost 4 years ago
Updated 25 April 2024, 7 months ago

Problem/Motivation

I have overwritten the quantity field with the jquery as found in the Belgrade theme provided with the Kickstart Demo (custom_form_element.js). This works for the "Add to cart" button but not in the fly-out cart itself.

Steps to reproduce

Overwrite the commerce-cart-flyout-offcanvas-contents-items.html.twig in the Belgrade templates; replace line 8 with:

<button class="number-btn decrement" type="button">-</button>
   <input class="form-control form-number" type="number" data-key="<% print(key) %>" min="1" value="<% print(parseInt(orderItem.quantity)) %>" />
<button class="number-btn increment" type="button">+</button>

Proposed resolution

Call the doCartUpdate() function from custom_form_element.js

Remaining tasks

Write a patch. I'm not sure how one should call the doCartUpdate function from an external script :-(

πŸ› Bug report
Status

Active

Version

1.8

Component

Miscellaneous

Created by

πŸ‡³πŸ‡±Netherlands solide-echt

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡¦Ukraine andriic

    change the value in input element and run. raw example

    const input = element.querySelector('input');
    input.value += 1;
    input.dispatchEvent(new window.Event('change', { bubbles: true }));
    setTimeout(() => {
      input.dispatchEvent(new window.Event('blur', { bubbles: true }));
    }, 200);
Production build 0.71.5 2024