1
0
Fork 0
mirror of synced 2024-07-09 00:06:05 +12:00

Fix initial validation

This commit is contained in:
Adria Navarro 2023-06-13 11:36:28 +01:00
parent 383c7c4b2c
commit e0664222fe

View file

@ -6,7 +6,6 @@ export function createValidationStore(initialValue, ...validators) {
let touched = false
const value = writable(initialValue || "")
const error = derived(value, $v => validate($v, validators))
const touchedStore = derived(value, () => {
if (!touched) {
touched = true
@ -14,6 +13,10 @@ export function createValidationStore(initialValue, ...validators) {
}
return touched
})
const error = derived(
[value, touchedStore],
([$v, $t]) => $t && validate($v, validators)
)
return [value, error, touchedStore]
}