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

Uncaught TypeError: Cannot read property 'forEach' of undefined #237

Closed
lorddaedra opened this issue Jul 9, 2021 · 4 comments · Fixed by #423
Closed

Uncaught TypeError: Cannot read property 'forEach' of undefined #237

lorddaedra opened this issue Jul 9, 2021 · 4 comments · Fixed by #423

Comments

@lorddaedra
Copy link

lorddaedra commented Jul 9, 2021

eventListeners.js:116 Uncaught TypeError: Cannot read property 'forEach' of undefined
    at HTMLDocument.<anonymous> (eventListeners.js:116)
(anonymous) @ eventListeners.js:116

      component.actionEvents[eventType].forEach((actionEvent) => {

I tried to use unicorn:click.discard="cancel" in child component.

@adamghill
Copy link
Owner

I do something similar in https://github.com/adamghill/django-unicorn/blob/master/example/unicorn/templates/unicorn/nested/row.html#L28. Can you replicate the error with my example or otherwise push an example to another repo so I can see what is going on? Thanks.

@adamghill
Copy link
Owner

Closing this for now because I can't replicate, but feel free to re-open if you can replicate in my example project. Thanks!

@clangley
Copy link
Contributor

clangley commented Aug 5, 2022

Hello, I've recently ran into this issue and created a simple project to reproduce this:
https://github.com/clangley/unicorn-typerror-example

  • I have 2 components, list_todos and edit_todos.
  • list_todos iterates over a handful of todos and renders a component for each.
  • You can edit the todos on the page and when you hit save it will save to the database.
  • After editing the first todo, it works and save correctly, any edits after will throw errors in console.

I have a small patch that will at least prevent throwing errors but it just checks for existence of eventType in component.actionEvents before doing the foreach. This appears to just work and solve the problem at the surface but not familiar enough with the code base to know if this is the correct fix or if it should be done elsewhere.

Happy to spend some time looking into this more because I am currently accessing Django Unicorn for an upcoming project.

@adamghill
Copy link
Owner

@clangley Thank you so much for the example code and fix! I tested it out and it looks great. I'm merging it into main now. 👍

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

Successfully merging a pull request may close this issue.

3 participants