|
I was trying to reproduce the tag (adding/removing from array) example. But the unsetField() was removing all items from tag array after the given index (including the index item). The desired behaviour is obtained only after tag input has "data-felte-keep-on-remove". Can anyone tell what exactly this do and provide link to the relevant source code files. |
Replies: 1 comment 1 reply
|
The source code that handles that is here. That attribute basically tells Felte to keep a field on its data object even if the DOM element is removed. The reason why it can be finicky with Another thing is that the code linked runs in a MutationObserver, which removes the field when the DOM element is removed. Since There might be a way to prevent this from being necessary but I have not looked into it. |
The source code that handles that is here. That attribute basically tells Felte to keep a field on its data object even if the DOM element is removed.
The reason why it can be finicky with
unsetFieldis that it can conflict with keyed lists. I believe it causes no issues in Svelte if you leave theeachblock without a key?Another thing is that the code linked runs in a MutationObserver, which removes the field when the DOM element is removed. Since
unsetFieldremoves the field from Felte'sdatastore, and since the easiest approach to render these lists is by iterating over the values themselves (e.g.{#each data.items as item}), adding thedata-felte-keep-on-removeis necessary for now.T…