Skip to content

Commit

Permalink
fix: correctly set the initial value from the v-model closes #3107
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Jan 5, 2021
1 parent cf43ce5 commit 4bed9a8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vee-validate/src/Field.ts
Expand Up @@ -91,7 +91,7 @@ export const Field = defineComponent({
// For checkboxes and radio buttons it will always be the model value not the `value` attribute
initialValue: hasCheckedAttr(ctx.attrs.type)
? props.modelValue
: 'modelValue' in ctx.attrs
: 'modelValue' in props
? props.modelValue
: ctx.attrs.value,
// Only for checkboxes and radio buttons
Expand Down
21 changes: 21 additions & 0 deletions packages/vee-validate/tests/Field.spec.ts
Expand Up @@ -868,4 +868,25 @@ describe('<Field />', () => {
await flushPromises();
expect(model.value).toBe(false);
});

// #3107
test('sets initial value with v-model', async () => {
const modelValue = 'allo';
const wrapper = mountWithHoc({
setup() {
const model = ref(modelValue);

return { model };
},
template: `
<div>
<Field name="whatever" v-model="model" />
</div>
`,
});

await flushPromises();
const input = wrapper.$el.querySelector('input');
expect(input.value).toBe(modelValue);
});
});

0 comments on commit 4bed9a8

Please sign in to comment.