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 binding on input in Component in {#each} loop uses data from first item in list #2971

Closed
LRNida opened this issue Jun 7, 2019 · 1 comment

Comments

@LRNida
Copy link

LRNida commented Jun 7, 2019

Situation: looping over a list of contact components with an {#each} loop. The contact component has a contact prop that is exported. Inside the contact component there is a checkbox that toggles the isFavourite status with an <input><label></label> structure;

Desired behaviour: putting an on:change={() => updateContact(contact)} on the input should result in the handler being called with the actual contact data that is shown.

What actually happens: the handler is always called with the data of the first contact in the list. This only happens (afaik) when the binding is on the input element. If the binding is on the label, the handler is called with the correct data.

Demo
The light grey cards are bugged examples (event on input), the dark grey work properly (event on label). See console to verify data in handler.

**Edit: ** Part of the mistake was using the same id="" for all inputs in the contacts. See here.
However, it's still strange that a component would get data from its sibling regardlesss.

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

No branches or pull requests

1 participant