-
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. |
Beta Was this translation helpful? Give feedback.
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. |
Beta Was this translation helpful? Give feedback.
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
unsetField
is that it can conflict with keyed lists. I believe it causes no issues in Svelte if you leave theeach
block 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
unsetField
removes the field from Felte'sdata
store, 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-remove
is necessary for now.T…