From aaabbf3fff698f0f7ca7993f9e42f52c67e1851c Mon Sep 17 00:00:00 2001 From: Jacob Wright Date: Mon, 10 Jun 2019 15:44:50 -0600 Subject: [PATCH] Fix 7 GUIs crud example for delete when filtered This example could delete the incorrect person when a filter was applied. Just an example, but the behavior was confusing when I played with it, so I thought it worth fixing. --- site/content/examples/19-7guis/05-7guis-crud/App.svelte | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/site/content/examples/19-7guis/05-7guis-crud/App.svelte b/site/content/examples/19-7guis/05-7guis-crud/App.svelte index a0d6ef7f3e..f55aeb0d83 100644 --- a/site/content/examples/19-7guis/05-7guis-crud/App.svelte +++ b/site/content/examples/19-7guis/05-7guis-crud/App.svelte @@ -43,10 +43,12 @@ } function remove() { - people = [...people.slice(0, i), ...people.slice(i + 1)]; + // Remove selected person from the source array (people), not the filtered array + const index = people.indexOf(selected); + people = [...people.slice(0, index), ...people.slice(index + 1)]; first = last = ''; - i = Math.min(i, people.length - 1); + i = Math.min(i, filteredPeople.length - 2); } function reset_inputs(person) {