Skip to content

Commit 4bed9a8

Browse files
committed
fix: correctly set the initial value from the v-model closes #3107
1 parent cf43ce5 commit 4bed9a8

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

packages/vee-validate/src/Field.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export const Field = defineComponent({
9191
// For checkboxes and radio buttons it will always be the model value not the `value` attribute
9292
initialValue: hasCheckedAttr(ctx.attrs.type)
9393
? props.modelValue
94-
: 'modelValue' in ctx.attrs
94+
: 'modelValue' in props
9595
? props.modelValue
9696
: ctx.attrs.value,
9797
// Only for checkboxes and radio buttons

packages/vee-validate/tests/Field.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,4 +868,25 @@ describe('<Field />', () => {
868868
await flushPromises();
869869
expect(model.value).toBe(false);
870870
});
871+
872+
// #3107
873+
test('sets initial value with v-model', async () => {
874+
const modelValue = 'allo';
875+
const wrapper = mountWithHoc({
876+
setup() {
877+
const model = ref(modelValue);
878+
879+
return { model };
880+
},
881+
template: `
882+
<div>
883+
<Field name="whatever" v-model="model" />
884+
</div>
885+
`,
886+
});
887+
888+
await flushPromises();
889+
const input = wrapper.$el.querySelector('input');
890+
expect(input.value).toBe(modelValue);
891+
});
871892
});

0 commit comments

Comments
 (0)