From b73519c5dbfcf926ad3fe560f31a8b0f8f801b4a Mon Sep 17 00:00:00 2001 From: Chaebean Yang Date: Sat, 7 Jun 2025 12:08:15 +0900 Subject: [PATCH] NewMemoryPopup error control --- src/lib/components/NewMemoryPopup.svelte | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lib/components/NewMemoryPopup.svelte b/src/lib/components/NewMemoryPopup.svelte index f954f67..2a8cc66 100644 --- a/src/lib/components/NewMemoryPopup.svelte +++ b/src/lib/components/NewMemoryPopup.svelte @@ -26,9 +26,17 @@ let customLocation = ''; let customLocationInput: HTMLInputElement; let images: File[] = []; - let showLocationError = false; let showImageError = false; + let hasAttemptedSubmit = false; + let isFormValid = true; + + $: if (hasAttemptedSubmit) { + isFormValid = ( + (selectedLocation !== '' && (!isCustomLocation() || customLocation.trim() !== '')) && + images.length > 0 + ); + } const GOOGLE_PLACES_API_KEY = import.meta.env.VITE_GOOGLE_PLACES_API_KEY; @@ -105,6 +113,8 @@ } async function handleAddMemory() { + hasAttemptedSubmit = true; + showLocationError = selectedLocation === '' || (isCustomLocation() && customLocation.trim() === ''); showImageError = images.length === 0; @@ -243,7 +253,7 @@