From 7fe81bc594798549c760227e6299d08042ae547a Mon Sep 17 00:00:00 2001 From: Nassim <71079376+nas-tabchiche@users.noreply.github.com> Date: Fri, 6 Dec 2024 20:45:42 +0100 Subject: [PATCH] Fix Score component tainting forms on mount (#1150) --- .../src/lib/components/Forms/Score.svelte | 36 ++++++------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/frontend/src/lib/components/Forms/Score.svelte b/frontend/src/lib/components/Forms/Score.svelte index e309ce9f9..950582e66 100644 --- a/frontend/src/lib/components/Forms/Score.svelte +++ b/frontend/src/lib/components/Forms/Score.svelte @@ -30,30 +30,15 @@ export let scores_definition: ScoresDefinition[] = []; - const tables = {}; - export let form: SuperForm>; const { value, errors, constraints } = formFieldProxy(form, field); - let isScoredField = formFieldProxy(form, `is_scored`)['value']; - let isScored: boolean; - if ($isScoredField === undefined) { - isScored = $value !== null; - } else { - isScored = $isScoredField; - $value = $value ?? min_score; - } + const isScored = formFieldProxy(form, `is_scored`)['value']; - function handleIsScoredChange() { - if ($isScoredField === undefined) { - $value = isScored ? $value || min_score : null; - } else { - $isScoredField = isScored; - } - } + $: $value = $isScored ? ($value ?? min_score) : $value; if (always_enabled) { - isScored = true; + $isScored = true; } $: if (max_score === 100) score_step = 5; @@ -93,13 +78,12 @@ max={max_score} step={score_step} ticked - disabled={!isScored} + disabled={!$isScored} >
{#if !always_enabled} {m.scoringHelpText()}

{/if} - {#if isScored && scores_definition && $value !== null} + {#if $isScored && scores_definition && $value !== null} {#each scores_definition as definition} {#if definition.score === $value}

@@ -120,20 +104,20 @@ {securityObjectiveDisplay($value) ?? (isScored ? $value : '--')}{securityObjectiveDisplay($value) ?? ($isScored ? $value : '--')} {:else} {isScored ? $value : '--'}{$isScored ? $value : '--'} {/if}