Browse Source

reword touched logic and export it as a store

master
Keviin Åberg Kultalahti 5 years ago
parent
commit
c450e5cd8a
  1. 13
      packages/builder/src/helpers/validation/validation.js

13
packages/builder/src/helpers/validation/validation.js

@ -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) {

Loading…
Cancel
Save