diff --git a/src/field/index.js b/src/field/index.js index 8289ef2c6..849611bb8 100644 --- a/src/field/index.js +++ b/src/field/index.js @@ -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 ( -
{inputSlot}
+
+ {this.inputSlot} +
); } diff --git a/src/form/test/field-type.spec.js b/src/form/test/field-type.spec.js index b41aedef5..7e1c1249d 100644 --- a/src/form/test/field-type.spec.js +++ b/src/form/test/field-type.spec.js @@ -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: ` + + + + + + + `, + methods: { + onSubmit, + }, + }); + + await submitForm(wrapper); + expect(onSubmit).toHaveBeenCalledWith({ A: 'foo' }); +});