1
0
Fork 0
mirror of synced 2024-07-07 23:35:49 +12:00

add touched check to validator

This commit is contained in:
Keviin Åberg Kultalahti 2021-05-11 18:03:14 +02:00
parent b10c41143f
commit 46cbba1cc0

View file

@ -1,9 +1,16 @@
import { writable, derived } from 'svelte/store'
export function createValidationStore(initialValue, ...validators) {
let touched = false
const value = writable(initialValue || '')
const error = derived(value, $v => validate($v, validators))
const error = derived(value, $v => {
if (touched) {
return validate($v, validators)
} else {
touched = true
}
})
return [value, error]
}