fix(Field): should not get formValue from button slot (#5785)

This commit is contained in:
chenjiahan 2020-03-09 19:18:16 +08:00
parent ecce907de7
commit 09ad95ca68
2 changed files with 35 additions and 4 deletions

View File

@ -125,7 +125,14 @@ export default createComponent({
},
formValue() {
return this.children ? this.children.value : this.value;
if (this.children && this.inputSlot) {
return this.children.value;
}
return this.value;
},
inputSlot() {
return this.slots('input');
},
},
@ -374,12 +381,13 @@ export default createComponent({
genInput() {
const { type } = this;
const inputSlot = this.slots('input');
const inputAlign = this.getProp('inputAlign');
if (inputSlot) {
if (this.inputSlot) {
return (
<div class={bem('control', [inputAlign, 'custom'])}>{inputSlot}</div>
<div class={bem('control', [inputAlign, 'custom'])}>
{this.inputSlot}
</div>
);
}

View File

@ -196,3 +196,26 @@ test('use uploader', async () => {
await submitForm(wrapper);
expect(onSubmit).toHaveBeenCalledWith({ A: [{ url: 'foo' }] });
});
test('should not get formValue from button slot', async () => {
const onSubmit = jest.fn();
const wrapper = mountForm({
template: `
<van-form @submit="onSubmit">
<van-field name="A" value="foo" :rules="[{ required: true, message: 'foo' }]">
<template #button>
<van-checkbox :value="false" />
</template>
</van-field>
<van-button native-type="submit" />
</van-form>
`,
methods: {
onSubmit,
},
});
await submitForm(wrapper);
expect(onSubmit).toHaveBeenCalledWith({ A: 'foo' });
});