Skip to content

Commit 6ab40df

Browse files
authored
fix: return value if no model modifiers are defined closes #3895 (#3896)
1 parent 97657b4 commit 6ab40df

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

packages/vee-validate/src/utils/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export function debounceAsync<TFunction extends (...args: any) => Promise<any>,
235235

236236
export function applyModelModifiers(value: unknown, modifiers: unknown) {
237237
if (!isObject(modifiers)) {
238-
return;
238+
return value;
239239
}
240240

241241
if (modifiers.number) {

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

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { defineRule } from '@/vee-validate';
1+
import { defineRule, useField } from '@/vee-validate';
22
import { mountWithHoc, setValue, setChecked, dispatchEvent, flushPromises } from './helpers';
33
import * as yup from 'yup';
4-
import { computed, onErrorCaptured, reactive, ref, Ref } from 'vue';
4+
import { computed, defineComponent, onErrorCaptured, reactive, ref, Ref } from 'vue';
55
import { InvalidSubmissionContext } from '../src/types';
66

77
describe('<Form />', () => {
@@ -2716,4 +2716,47 @@ describe('<Form />', () => {
27162716
expect(inputAt(2).checked).toBe(true);
27172717
expect(inputAt(3).checked).toBe(false);
27182718
});
2719+
2720+
// #3895 #3894
2721+
test('single checkbox component with v-model in a form', async () => {
2722+
const value = ref(false);
2723+
const Checkbox = defineComponent({
2724+
props: { value: Boolean, modelValue: Boolean },
2725+
template: `<input type="checkbox" @change="handleChange" :checked="checked" :value="true" />`,
2726+
setup() {
2727+
const { handleChange, checked } = useField('field', undefined, {
2728+
type: 'checkbox',
2729+
uncheckedValue: false,
2730+
checkedValue: true,
2731+
});
2732+
2733+
return {
2734+
handleChange,
2735+
checked,
2736+
};
2737+
},
2738+
});
2739+
const wrapper = mountWithHoc({
2740+
components: {
2741+
Checkbox,
2742+
},
2743+
setup() {
2744+
return {
2745+
value,
2746+
};
2747+
},
2748+
template: `
2749+
<VForm>
2750+
<Checkbox v-model="value" />
2751+
</VForm>
2752+
`,
2753+
});
2754+
2755+
await flushPromises();
2756+
const inputAt = (idx: number) => wrapper.$el.querySelectorAll('input')[idx] as HTMLInputElement;
2757+
expect(value.value).toBe(false);
2758+
setChecked(inputAt(0), true);
2759+
await flushPromises();
2760+
expect(value.value).toBe(true);
2761+
});
27192762
});

0 commit comments

Comments
 (0)