Custom component with v-model and useField (was working on v4.8.6, but not on v4.11.1 anymore) #4404
-
I want to use a custom component receiving a reactive value (both-ways) via I was using the solution proposed here: this was working as of v4.8.6, but after upgrading to v4.11.1,changing the value via v-model does not get realized by vee-validate anymore and does anyone have a hint on a possible solution? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Check this part in the documentation and let me know if it works for you. |
Beta Was this translation helpful? Give feedback.
-
@logaretm After upgrading from v4.11.3 to 4.11.4 this seems to have stopped working again. i assume it could have something to do with the fix "Respect validateOnModelUpdate configuration"? But config says it's default is true, and i'm not changing it in my app. here is my component (using vuetify): <script setup lang="ts">
import { defineProps, toRef } from 'vue'
import { useField } from 'vee-validate'
const props = defineProps({
name: {
type: String,
required: true,
},
type: {
type: String,
required: false,
default: 'text',
},
label: {
type: String,
required: false,
default: undefined,
},
clearable: {
type: Boolean,
required: false,
default: true,
},
modelValue: {
type: [String, Object],
default: '',
},
})
const emit = defineEmits(['update:modelValue'])
const {
value: inputValue,
handleBlur,
handleChange,
errors,
} = useField(toRef(props, 'name'), undefined, {
label: props.label,
syncVModel: true,
})
const onInput = (event) => {
handleChange(event, true)
emit('update:modelValue', event)
}
</script>
<template>
<v-text-field
:model-value="inputValue"
:label="label"
:error-messages="errors"
hide-details="auto"
:type="type"
:clearable="clearable"
persistent-hint
:name="name"
@blur="handleBlur"
@input="onInput($event)"
@update:modelValue="onInput($event)"
>
<template v-if="$slots.prepend" #prepend>
<slot name="prepend" />
</template>
<template v-if="$slots.append" #append>
<slot name="append" />
</template>
<template v-if="$slots['prepend-inner']" #prepend-inner>
<slot name="prepend-inner" />
</template>
<template v-if="$slots['append-inner']" #append-inner>
<slot name="append-inner" />
</template>
<template v-if="$slots.details" #details>
<slot name="details" />
</template>
</v-text-field>
</template> |
Beta Was this translation helpful? Give feedback.
-
Sure, no problem: https://stackblitz.com/edit/wsnaxt?file=src%2FInputText.vue I forked your v-model example and adapted it. Many thanks for taking a look at it! |
Beta Was this translation helpful? Give feedback.
Check this part in the documentation and let me know if it works for you.