Skip to content

Commit

Permalink
feat: add validateOnValueUpdate option
Browse files Browse the repository at this point in the history
  • Loading branch information
nozomuikuta committed Jan 5, 2024
1 parent 2cf3610 commit b95530b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/vue-v8n/src/composables/useV7d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export function useV7d<T>(value: T, rules: MaybeRefOrGetter<RuleDefinition[]>, o
const {
immediate = false,
touchOnFocus = true,
validateOnBlur = true
validateOnBlur = true,
validateOnValueUpdate = true
} = options || {}

const $el = ref<EventTarget>()
Expand All @@ -23,7 +24,9 @@ export function useV7d<T>(value: T, rules: MaybeRefOrGetter<RuleDefinition[]>, o
}, { immediate: true })
}

watch(_value, $validate, { immediate })
if (validateOnValueUpdate) {
watch(_value, $validate, { immediate })
}

watch(_rules, $validate)

Expand Down
1 change: 1 addition & 0 deletions packages/vue-v8n/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface UseV7dOptions {
immediate?: boolean
touchOnFocus?: boolean
validateOnBlur?: boolean
validateOnValueUpdate?: boolean
}

export interface VueV8nOptions {}
Expand Down
3 changes: 2 additions & 1 deletion playground/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ const noEventListeningNameRuleOptions = ref([
])
const noEventListeningName = useV7d('', computed(() => noEventListeningNameRuleOptions.value.flatMap(({ selected, rule }) => selected ? [rule] : [])), {
touchOnFocus: false,
validateOnBlur: false
validateOnBlur: false,
validateOnValueUpdate: false,
})
watch(noEventListeningNameRuleOptions, () => validatedValues.noEventListeningName = noEventListeningName.$validate(), { deep: true })
Expand Down

0 comments on commit b95530b

Please sign in to comment.