mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Field): should not get formValue from button slot (#5785)
This commit is contained in:
parent
ecce907de7
commit
09ad95ca68
@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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' });
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user