From 408226a55d1086055a3d79f5708e63cddc4a3cd2 Mon Sep 17 00:00:00 2001 From: rgsk Date: Mon, 25 Mar 2024 11:27:27 +0530 Subject: [PATCH] show save button when form is changed --- .../routes/settings/Settings/Settings.svelte | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/ui/src/routes/settings/Settings/Settings.svelte b/ui/src/routes/settings/Settings/Settings.svelte index 9707e363..fe4777fd 100644 --- a/ui/src/routes/settings/Settings/Settings.svelte +++ b/ui/src/routes/settings/Settings/Settings.svelte @@ -3,18 +3,19 @@ import { getSettings, setSettings } from "../../../lib/api"; import Button from "./Button.svelte"; import Input from "./Input.svelte"; - let result; - let settingsLoading; + let result: any; + let settingsLoading: boolean; onMount(async () => { result = await getSettings(); - console.log(result); + // console.log(result); }); async function handleSubmit() { settingsLoading = true; const postResult = await setSettings(result); - console.log(postResult); + // console.log(postResult); settingsLoading = false; + formChanged = false; } function checkNonEmptyRecursive(obj) { for (const key in obj) { @@ -31,6 +32,7 @@ return true; } $: formValid = checkNonEmptyRecursive(result); + let formChanged = false;
@@ -46,6 +48,9 @@ label={key} type="text" bind:value={result[mainKey][key]} + on:input={() => { + formChanged = true; + }} error={!result[mainKey][key] ? "field can't be empty" : ""} /> {/each} @@ -59,13 +64,15 @@
{/if} - + {#if formChanged} + + {/if} {/if}