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

reword touched logic and export it as a store

This commit is contained in:
Keviin Åberg Kultalahti 2021-05-11 18:08:55 +02:00
parent 2b3c4ee2bc
commit c450e5cd8a

View file

@ -4,15 +4,16 @@ export function createValidationStore(initialValue, ...validators) {
let touched = false
const value = writable(initialValue || '')
const error = derived(value, $v => {
if (touched) {
return validate($v, validators)
} else {
const error = derived(value, $v => validate($v, validators))
const touchedStore = derived(value, () => {
if (!touched) {
touched = true
}
return
}
return touched
})
return [value, error]
return [value, error, touchedStore]
}
function validate(value, validators) {