From b01e7f231d91c75539815a71ef5802a981ab6a20 Mon Sep 17 00:00:00 2001 From: Arman Date: Wed, 12 Jun 2024 18:02:31 +0200 Subject: [PATCH] fix: apply credit flow --- .../billing/selectPaymentMethod.svelte | 4 +-- .../elements/forms/inputSelectSearch.svelte | 18 +++++++++- src/routes/console/apply-credit/+page.svelte | 36 +++++++++---------- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/lib/components/billing/selectPaymentMethod.svelte b/src/lib/components/billing/selectPaymentMethod.svelte index ccd4f4a9e..bd3963b09 100644 --- a/src/lib/components/billing/selectPaymentMethod.svelte +++ b/src/lib/components/billing/selectPaymentMethod.svelte @@ -17,7 +17,7 @@ let input: HTMLInputElement; let error: string; - const handleInvalid = (event: Event) => { + function handleInvalid(event: Event) { event.preventDefault(); if (input.validity.valueMissing) { @@ -25,7 +25,7 @@ return; } error = input.validationMessage; - }; + } async function cardSaved(event: CustomEvent) { value = event.detail.$id; diff --git a/src/lib/elements/forms/inputSelectSearch.svelte b/src/lib/elements/forms/inputSelectSearch.svelte index 5d6f886ec..f9dfc2865 100644 --- a/src/lib/elements/forms/inputSelectSearch.svelte +++ b/src/lib/elements/forms/inputSelectSearch.svelte @@ -2,7 +2,7 @@ import { DropList } from '$lib/components'; import { clickOnEnter } from '$lib/helpers/a11y'; import { createEventDispatcher, onMount } from 'svelte'; - import { Label } from '.'; + import { Helper, Label } from '.'; /* eslint no-undef: "off" */ type Option = $$Generic<{ @@ -36,6 +36,7 @@ let element: HTMLInputElement; let hasFocus = false; let selected: number = null; + let error: string; $: if (!hasFocus) { selected = null; @@ -105,7 +106,18 @@ dispatch('reset'); } + function handleInvalid(event: Event) { + event.preventDefault(); + + if (element.validity.valueMissing) { + error = 'This field is required'; + return; + } + error = element.validationMessage; + } + $: showClearBtn = (hasFocus && search) || value; + $: if (value || search) error = null;
  • (hasFocus = true)} on:click={() => (hasFocus = true)} + on:invalid={handleInvalid} on:input={handleInput} on:keydown={handleKeydown} /> {/if} @@ -205,6 +218,9 @@ {/if} + {#if error} + {error} + {/if}