Skip to content

Raising the change event on button click #3

Description

@bigvax

Thanks for the useful widget.
I had to catch the input value change for the reaction in my script.
Unfortunately, the widget did not provide such functionality.
And I added it to the widget.

*** 86,102 ****
       wrapper.querySelector(".plus-btn").addEventListener("click", function(){
          newInputVal = parseInt(numInput.value, 10) + step;
          if (newInputVal <= maxVal) {
              numInput.value = newInputVal;
          }
      })

      wrapper.querySelector(".minus-btn").addEventListener("click", function(){
          newInputVal = parseInt(numInput.value, 10) - step;
          if (newInputVal >= minVal) {
              numInput.value = newInputVal;
          }
      })
  });
--- 86,102 ----
       wrapper.querySelector(".plus-btn").addEventListener("click", function(){
          newInputVal = parseInt(numInput.value, 10) + step;
          if (newInputVal <= maxVal) {
              numInput.value = newInputVal;
+             numInput.dispatchEvent(new Event('change'));
          }
      })

      wrapper.querySelector(".minus-btn").addEventListener("click", function(){
          newInputVal = parseInt(numInput.value, 10) - step;
          if (newInputVal >= minVal) {
              numInput.value = newInputVal;
+             numInput.dispatchEvent(new Event('change'));
          }
      })
  });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions