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