-
- Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
bind:group on input checkbox not working as expected inside nested loop
Describe the bug
Currently I create dynamic checkbox based on nested array. I want to make role management with just check the action (C,R,U,or D) based on module. This is the minimal example of the data
[ { key: "p1", checked: [], sub: [ { key: "p1s1", checked: [] }] }, { key: "p2", checked: [], sub: [ { key: "p1s1", checked: [] }] } ]
p1 will be parent module, and p1s1 is sub module for p1. Then i loop that array to create input checkbox. For parent checkbox the behaviour is ok as expected. But for the nested one is not working as expected. I think the index of bind:group of nested checkbox is collapse with the other.
For example:
p1s1 has checked value ["C"], when I check "R" on p2s1 (same sub index but different parent), the value of p2s1 checked is ["C","R"].
To Reproduce
this is the REPL link for the demo https://svelte.dev/repl/8d03a86642e449108c2dd22de7aa8cd3?version=3.31.0
- check p1s1 C
- check p2s1 R
you will see, p2s1 C is checked (if you check p1s1 D first, you will see p2s1 D checked)
Expected behavior
only p2s1 R is checked
Stacktraces
If you have a stack trace to include, we recommend putting inside a <details>
block for the sake of the thread's readability:
Stack trace
Stack trace goes here...
Information about your Svelte project:
To make your life easier, just run npx envinfo --system --npmPackages svelte,rollup,webpack --binaries --browsers
and paste the output here.
System:
OS: macOS 11.0.1
CPU: (4) x64 Intel(R) Core(TM) i5-5300U CPU @ 2.30GHz
Memory: 212.89 MB / 8.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.4.0 - ~/.nvm/versions/node/v14.4.0/bin/node
Yarn: 1.22.5 - ~/.yarn/bin/yarn
npm: 6.14.5 - ~/.nvm/versions/node/v14.4.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Browsers:
Chrome: 87.0.4280.88
Firefox: 83.0
Safari: 14.0.1
npmPackages:
rollup: ^2.3.4 => 2.33.1
svelte: ^3.31.0 => 3.31.0
Severity
Not urgent, but is annoying
Current Work around
when i change bind:group on nested loop from s.checked
to d.sub[i].checked
this issue is gone