-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
Listen to on:delete event of some sort? #204
Comments
Hi, thanks for support! Regarding your question. There is no such event (existing or planned) or another built-in way to determine what was deleted... So the way you are describing is the only way. And basically the correct one. |
This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 3 days. |
To be honest I've been struggling with creating the logic for this for a while since I want to post to the form action Could you please give me a hint on how could I do that? I've been trying all sort of approaches, just can't figure it out: let allTags = data.allTags
let assignedTags = data.assignedTags
let localTags = [...allTags]
let localAssignedTags = [...assignedTags]
let tagToRemove = {}
const handleChange = (event) => {
// event.detail always returns the localAssignedTags array
let tagsInQuestion = event.detail.map((tag) => ({
...tag,
isSelected: localTags.some((localTag) => localTag.id === tag.id)
}))
// Find tags that were removed
tagToRemove = assignedTags.find(
(tag) => !tagsInQuestion.some((tagInQuestion) => tagInQuestion.id === tag.id)
)
if (tagToRemove) {
console.log('-- tag was removed', tagToRemove.title)
} else {
console.log('++ tag was added', tagsInQuestion.title)
}
localAssignedTags = tagsInQuestion
}
<Svelecte
options={localTags}
bind:value={localAssignedTags}
multiple={true}
creatable={true}
on:change={(event) => handleChange(event)}
allowEditing={true}
> The trouble with this one is that it never meets the tagToRemove condition. Here's a sort of a working repl https://www.sveltelab.dev/efd6psbixsri3ws?files=.%2Fsrc%2Froutes%2F%2Bpage.svelte%2C.%2Fsrc%2Froutes%2F%2Bpage.server.js. |
Like this one... updated sveltelab.dev example Basically you need to store also the previous selection. Also I think your functions to filter the tag added/removed were slightly off, so I did my own in the example. Hope it helps |
Thanks for correcting the filtering function, @mskocik! Sorry if this is getting out of the library context itself, but even in your example the input values aren't being populated when there's a created or selected from the existing list tag added? That's why I was initially thinking if splitting into |
Re: value isn't populated, I think that was because we were checking |
To clarify... so my example is enough for you? Btw at least in the console you can always see items which were removed (in my example of course) |
This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 3 days. |
Hey first of all—this is the best multiselect plugin for Svelte. For the past few weeks I tried at least 5 different ones, and was able to get running with svelecte in minutes. So thank you!
But I'm curious about listening to the
on:delete
changes. In my case, user already lands on a list with a filledvalue
array, and moreoptions
too. They can also create new options, and remove pre-selected tags.Event from the
on:change
when clicked on a tag to delete it exposes the entirevalue
array and not just the clicked tag. Is there a better way to do this other comparing value arrays (old vs new) and then pull out ids to then process for deletion?The text was updated successfully, but these errors were encountered: