From 3beefa592d4682589677be03b8aedd69bb12b4a2 Mon Sep 17 00:00:00 2001 From: Allan Lasser Date: Tue, 10 Dec 2024 14:21:28 -0500 Subject: [PATCH 1/2] Prefill add-on fields from query params Fixes #965 --- src/lib/components/forms/AddOnDispatch.svelte | 7 +++++++ .../stories/AddOnDispatch.stories.svelte | 20 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/lib/components/forms/AddOnDispatch.svelte b/src/lib/components/forms/AddOnDispatch.svelte index 8390898ed..67765bc9d 100644 --- a/src/lib/components/forms/AddOnDispatch.svelte +++ b/src/lib/components/forms/AddOnDispatch.svelte @@ -14,6 +14,7 @@ } from "$lib/api/types"; import { enhance } from "$app/forms"; + import { page } from "$app/stores"; import { afterNavigate } from "$app/navigation"; import Ajv from "ajv"; @@ -51,6 +52,12 @@ $: validator = ajv.compile({ type: "object", properties, required }); $: hasEvents = eventOptions && eventOptions.events.length > 0; $: hasFields = Object.keys(properties).length > 0; + // prefill values from search params + $: new URLSearchParams($page.url.searchParams).forEach((v, k) => { + if (k in properties) { + $values[k] = v; + } + }); afterNavigate(() => { // set initial values diff --git a/src/lib/components/forms/stories/AddOnDispatch.stories.svelte b/src/lib/components/forms/stories/AddOnDispatch.stories.svelte index 769dbcd6b..561dfefc5 100644 --- a/src/lib/components/forms/stories/AddOnDispatch.stories.svelte +++ b/src/lib/components/forms/stories/AddOnDispatch.stories.svelte @@ -5,6 +5,7 @@ import Flex from "$lib/components/common/Flex.svelte"; import { addonsList } from "@/test/fixtures/addons"; + import { APP_URL } from "@/config/config"; const addons = addonsList.results; @@ -26,7 +27,7 @@ required={addon.parameters.required} eventOptions={addon.parameters.eventOptions} /> -
+

$values

{JSON.stringify($values, null, 2)}
@@ -46,3 +47,20 @@ + + From 2da28854a0a817d9ae857d47e43843cbad830463 Mon Sep 17 00:00:00 2001 From: Allan Lasser Date: Tue, 10 Dec 2024 14:39:57 -0500 Subject: [PATCH 2/2] Prefill afterNavigate --- src/lib/components/forms/AddOnDispatch.svelte | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/components/forms/AddOnDispatch.svelte b/src/lib/components/forms/AddOnDispatch.svelte index 67765bc9d..57d65c28f 100644 --- a/src/lib/components/forms/AddOnDispatch.svelte +++ b/src/lib/components/forms/AddOnDispatch.svelte @@ -52,12 +52,6 @@ $: validator = ajv.compile({ type: "object", properties, required }); $: hasEvents = eventOptions && eventOptions.events.length > 0; $: hasFields = Object.keys(properties).length > 0; - // prefill values from search params - $: new URLSearchParams($page.url.searchParams).forEach((v, k) => { - if (k in properties) { - $values[k] = v; - } - }); afterNavigate(() => { // set initial values @@ -67,6 +61,12 @@ event: schedules[event.event], }; } + // prefill values from search params + new URLSearchParams($page.url.searchParams).forEach((v, k) => { + if (k in properties) { + $values[k] = v; + } + }); }); function objectify(params: any) {