|
|
@@ -0,0 +1,31 @@
|
|
|
+<script lang="ts">
|
|
|
+ import type { AppointmentInputs } from "$lib/dbdata";
|
|
|
+
|
|
|
+ let dynamicInputs: AppointmentInputs[] = [
|
|
|
+ {name: "First name", type: "text"},
|
|
|
+ {name: "Last name", type: "text"},
|
|
|
+ {name: "E-Mail", type: "email"}
|
|
|
+ ];
|
|
|
+
|
|
|
+ let inputValues: Record<string, string> = {};
|
|
|
+
|
|
|
+ function submit() {
|
|
|
+ const jsonOutput: Record<string, any> = {};
|
|
|
+ for (const dInput of dynamicInputs) {
|
|
|
+ if (inputValues[dInput.name]) {
|
|
|
+ jsonOutput[dInput.name] = inputValues[dInput.name];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log(jsonOutput); // Output the JSON object
|
|
|
+ }
|
|
|
+
|
|
|
+</script>
|
|
|
+
|
|
|
+{#each dynamicInputs as dInput, index}
|
|
|
+ <div class="field border">
|
|
|
+ <input id={dInput.name} type={dInput.type} placeholder={dInput.name} bind:value={inputValues[dInput.name]}>
|
|
|
+ <label for={dInput.name}>{dInput.name}</label>
|
|
|
+ </div>
|
|
|
+{/each}
|
|
|
+
|
|
|
+<button on:click={submit}>Submit</button>
|