Browse Source

fix: tag validation

Timothy J. Baek 1 year ago
parent
commit
2fbb92aceb
1 changed files with 9 additions and 3 deletions
  1. 9 3
      src/lib/components/common/Tags/TagInput.svelte

+ 9 - 3
src/lib/components/common/Tags/TagInput.svelte

@@ -1,6 +1,7 @@
 <script lang="ts">
 	import { createEventDispatcher, getContext } from 'svelte';
 	import { tags } from '$lib/stores';
+	import { toast } from 'svelte-sonner';
 	const dispatch = createEventDispatcher();
 
 	const i18n = getContext('i18n');
@@ -10,9 +11,14 @@
 	let tagName = '';
 
 	const addTagHandler = async () => {
-		dispatch('add', tagName);
-		tagName = '';
-		showTagInput = false;
+		tagName = tagName.trim();
+		if (tagName !== '') {
+			dispatch('add', tagName);
+			tagName = '';
+			showTagInput = false;
+		} else {
+			toast.error('Invalid Tag');
+		}
 	};
 </script>