From d5152643b05227e001a721952508854d0404c7fb Mon Sep 17 00:00:00 2001 From: Jirawat Boonkumnerd Date: Sat, 24 Feb 2024 22:30:34 +0700 Subject: [PATCH] feat: add validate input on blur before the input validate on submit, this commit make it validate on input blur, I have tried on change but after focus on the input again the error is gone. and if the input didn't change it's not trigger validate again. --- packages/shared/components/SelectorInput.svelte | 4 ++++ .../shared/components/inputs/AmountInput.svelte | 4 ++++ .../components/inputs/AssetAmountInput.svelte | 1 + packages/shared/components/inputs/Input.svelte | 5 ++++- .../shared/components/inputs/NumberInput.svelte | 4 ++++ .../components/inputs/RecipientInput.svelte | 1 + .../shared/components/inputs/TextInput.svelte | 15 ++++++++++++++- 7 files changed, 32 insertions(+), 2 deletions(-) diff --git a/packages/shared/components/SelectorInput.svelte b/packages/shared/components/SelectorInput.svelte index e967e5e7d49..5f0fdcb68ea 100644 --- a/packages/shared/components/SelectorInput.svelte +++ b/packages/shared/components/SelectorInput.svelte @@ -3,6 +3,7 @@ import { Modal, TextInput, Text, TextType, FontWeight, IOption } from 'shared/components' import { fade } from 'svelte/transition' import { truncateString } from '@core/utils' + import { createEventDispatcher } from 'svelte' export let labelLocale: string export let options: IOption[] @@ -16,6 +17,8 @@ // If the attribute is set to false, HTML interprets it as a readonly field. export let readonly: boolean | null = null + const dispatch = createEventDispatcher() + let value: string = selected?.key ?? selected?.value ?? '' let previousValue: string = value let hasFocus: boolean @@ -73,6 +76,7 @@ placeholder={localize(labelLocale)} fontSize="sm" {readonly} + on:blur={() => dispatch('blur')} {...$$restProps} >
diff --git a/packages/shared/components/inputs/AmountInput.svelte b/packages/shared/components/inputs/AmountInput.svelte index 10e1d4ec3f0..20e15e2fb1d 100644 --- a/packages/shared/components/inputs/AmountInput.svelte +++ b/packages/shared/components/inputs/AmountInput.svelte @@ -1,5 +1,6 @@ dispatch('blur')} {...$$restProps} > diff --git a/packages/shared/components/inputs/RecipientInput.svelte b/packages/shared/components/inputs/RecipientInput.svelte index e39d94c7d9d..f6ef722c918 100644 --- a/packages/shared/components/inputs/RecipientInput.svelte +++ b/packages/shared/components/inputs/RecipientInput.svelte @@ -74,6 +74,7 @@ {disabled} options={accountOptions} pickerHeight="max-h-48" + on:blur={() => validate()?.catch((err) => console.error(err))} {...$$restProps} let:option > diff --git a/packages/shared/components/inputs/TextInput.svelte b/packages/shared/components/inputs/TextInput.svelte index 12507716d33..a5d0d25ad46 100644 --- a/packages/shared/components/inputs/TextInput.svelte +++ b/packages/shared/components/inputs/TextInput.svelte @@ -1,4 +1,5 @@ - + dispatch('blur')} + {...$$restProps} +>