Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

event listen fire multiple times #5221

Closed
massimoliani opened this issue Nov 3, 2019 · 10 comments
Closed

event listen fire multiple times #5221

massimoliani opened this issue Nov 3, 2019 · 10 comments
Labels

Comments

@massimoliani
Copy link

On the new version of MDCSelect is not possible to use anymore tag. Using I have to insert the onchange event on the listened of MDCSelect class. When registering the event handler the system fire many and many onchange event everytime I make a change. I've seen this multiple event firing on some other components too implementing the listening paradigm. Any possible solutions? Thank you.

@treminaor
Copy link

What was the resolution? I am having this issue too.

@allan-chen
Copy link
Contributor

Are you on the latest release?

@allan-chen
Copy link
Contributor

#5570 and #5783 may be relevant. Both issues are resolved as of 7.0

@treminaor
Copy link

Assuming the CDN link is the latest release I am yes.
<script src="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.js"></script>`

@treminaor
Copy link

Also it happens 8 times consistently on my end. If I create the MDCSelect:change event myself and dispatch it then it only fires once, behaving normally.

@allan-chen
Copy link
Contributor

Here's a codepen where it seems to be behaving as expected: https://codepen.io/allanchenmdc/pen/MWKEqrK

Please feel free to fork it to reproduce your issue.

@bonniezhou bonniezhou removed their assignment Jul 6, 2020
@luclorencini-zz
Copy link

Also it happens 8 times consistently on my end. If I create the MDCSelect:change event myself and dispatch it then it only fires once, behaving normally.

It's happering eigth times with me as well.

$(document).ready(function () {
const select = new mdc.select.MDCSelect(document.querySelector('#NivelAcesso'));
select.listen('MDCSelect:change', () => {
alert('hello');
});
})

This fire 8 alerts on screen.

@allan-chen
Copy link
Contributor

allan-chen commented Jul 13, 2020

@luclorencini - I have modified this codepen to include a version of your code and it only seems to fire once. Please feel free to fork it to reproduce your issue: https://codepen.io/allanchenmdc/pen/MWKEqrK

@treminaor
Copy link

@luclorencini - I have modified this codepen to include a version of your code and it only seems to fire once. Please feel free to fork it to reproduce your issue: https://codepen.io/allanchenmdc/pen/MWKEqrK

Is it possible we are doing something wrong which would produce this behavior in our local environments? I didn't reply anymore because I could not reproduce the issue in codepen. I fixed my local code with a "hack" to ignore the 7 erroneous event fires but that's not a fix it's just a bandaid.

@allan-chen
Copy link
Contributor

allan-chen commented Jul 13, 2020

Hi @treminaor,

From your previous comment it seems like you're using CDN for the latest version, and if that's confirmed we can rule out any MDC build problems or versioning issues (all components, esp select, menu, and list, must be at v7). I would try to get the absolute bare minimal version of the component running locally - with just the HTML and JS from the codepen + MDC CDN to start and see if the issue persists.

In essence, we're trying to first get an equivalent environment to the codepen locally, then see what digressions we can see from there.

CDN links reproduced for your ref:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants