Skip to content

Commit

Permalink
fix: handle absent model value closes #3468
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Aug 31, 2021
1 parent 508a3db commit e2f903e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vee-validate/src/Field.ts
Expand Up @@ -173,7 +173,7 @@ export const Field = defineComponent({
}

if (newModelValue !== applyModifiers(value.value, props.modelModifiers)) {
value.value = newModelValue;
value.value = (newModelValue as any) === IS_ABSENT ? undefined : newModelValue;
validateField();
}
});
Expand Down
24 changes: 24 additions & 0 deletions packages/vee-validate/tests/Field.spec.ts
Expand Up @@ -1067,4 +1067,28 @@ describe('<Field />', () => {
await flushPromises();
expect(value.value).toBe(false);
});

// #3468
test('should avoid setting the absent value to Vue', async () => {
const form = ref({});
const wrapper = mountWithHoc({
setup() {
return {
form,
};
},
template: `
<Field v-model="form.value" name="hello" />
`,
});

await flushPromises();
const input = document.querySelector('input') as HTMLInputElement;
setValue(input, '1234');
await flushPromises();
expect(input.value).toBe('1234');
form.value = {};
await flushPromises();
expect(input.value).toBe('');
});
});

0 comments on commit e2f903e

Please sign in to comment.