add touched check to validator

This commit is contained in:
Keviin Åberg Kultalahti 2021-05-11 18:03:14 +02:00
parent f2e6259bb7
commit cd2b5128f5
1 changed files with 8 additions and 1 deletions

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]
}