CreatorInputs.svelte 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <script lang="ts">
  2. import type { AppointmentInputs } from '$lib/dbdata';
  3. import { onMount } from 'svelte';
  4. import AppointmentInfo from './AppointmentInfo.svelte';
  5. import { getTimeSlots } from '$lib/funcs';
  6. import { t } from '$lib/translations';
  7. export let creatorInputs: AppointmentInputs[] = [{ name: '', type: 'text' }];
  8. function addInput() {
  9. const newInput: AppointmentInputs = { name: '', type: 'text' };
  10. creatorInputs = [...creatorInputs, newInput];
  11. }
  12. function removeInput(indexToRemove: number) {
  13. // creatorInputs.splice(index, 1);
  14. creatorInputs = creatorInputs.filter((_, index) => index !== indexToRemove);
  15. }
  16. </script>
  17. <fieldset>
  18. <legend>{$t("common.inputs")}</legend>
  19. <button on:click={addInput} class="large circle tertiary">
  20. <i>add</i>
  21. </button>
  22. <div class="grid">
  23. {#each creatorInputs as customInput, index}
  24. <div class="s12">
  25. <div class="row bottom-margin">
  26. <div class="max field border">
  27. <input bind:value={customInput.name} id="custom-input" />
  28. <label for="custom-input">{$t("common.input-field")}</label>
  29. </div>
  30. <div class="max field border">
  31. <select bind:value={customInput.type} id="custom-type">
  32. <option value="text">{$t("common.text-input")}</option>
  33. <option value="email">{$t("common.email")}</option>
  34. <option value="tel">{$t("common.phone-number")}</option>
  35. </select>
  36. <label for="custom-type">{$t("common.input-type")}</label>
  37. </div>
  38. <button on:click={() => removeInput(index)} class="circle error medium m1">
  39. <i>delete</i>
  40. </button>
  41. </div>
  42. </div>
  43. {/each}
  44. </div>
  45. </fieldset>