Skip to content

unsetField(), what exactly is data-felte-keep-on-remove ? #190

Answered by pablo-abc
squiba36 asked this question in Q&A
Discussion options

You must be logged in to vote

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 the each 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's data 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 the data-felte-keep-on-remove is necessary for now.

T…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@squiba36
Comment options

Answer selected by squiba36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants