NewMemoryPopup error control
This commit is contained in:
parent
c7c4153220
commit
b73519c5db
|
@ -26,9 +26,17 @@
|
||||||
let customLocation = '';
|
let customLocation = '';
|
||||||
let customLocationInput: HTMLInputElement;
|
let customLocationInput: HTMLInputElement;
|
||||||
let images: File[] = [];
|
let images: File[] = [];
|
||||||
|
|
||||||
let showLocationError = false;
|
let showLocationError = false;
|
||||||
let showImageError = 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;
|
const GOOGLE_PLACES_API_KEY = import.meta.env.VITE_GOOGLE_PLACES_API_KEY;
|
||||||
|
|
||||||
|
@ -105,6 +113,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleAddMemory() {
|
async function handleAddMemory() {
|
||||||
|
hasAttemptedSubmit = true;
|
||||||
|
|
||||||
showLocationError = selectedLocation === '' || (isCustomLocation() && customLocation.trim() === '');
|
showLocationError = selectedLocation === '' || (isCustomLocation() && customLocation.trim() === '');
|
||||||
showImageError = images.length === 0;
|
showImageError = images.length === 0;
|
||||||
|
|
||||||
|
@ -243,7 +253,7 @@
|
||||||
<Button text="Cancel" type="gray" onClick={handleCancelClick} />
|
<Button text="Cancel" type="gray" onClick={handleCancelClick} />
|
||||||
<Button text="Add a new memory" type="orange"
|
<Button text="Add a new memory" type="orange"
|
||||||
onClick={handleAddMemory}
|
onClick={handleAddMemory}
|
||||||
disabled={showLocationError || showImageError}/>
|
disabled={hasAttemptedSubmit && !isFormValid}/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user