Skip to content

Commit

Permalink
feat: form组件增加submit事件回调及取消默认行为 (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocean-gao authored Aug 11, 2023
1 parent 7f660ad commit 5a566fa
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
12 changes: 10 additions & 2 deletions components/form/form.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<form :class="formClass" :style="formStyle">
<form :class="formClass" :style="formStyle" @submit="handleSubmit">
<slot />
</form>
</template>
Expand All @@ -20,7 +20,8 @@ const prefixCls = getPrefixCls('form');
export default defineComponent({
name: FORM_NAME,
props: formProps,
setup(props) {
emits: ['submit'],
setup(props, { emit }) {
useTheme();
const formFields: {
Expand Down Expand Up @@ -130,13 +131,20 @@ export default defineComponent({
removeField,
});
const handleSubmit = (e: Event) => {
e.preventDefault();
e.stopPropagation();
emit('submit', e);
};
return {
formClass,
formStyle,
validate,
clearValidate,
resetFields,
handleSubmit,
};
},
});
Expand Down
6 changes: 6 additions & 0 deletions docs/.vitepress/components/form/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ Form 组件提供表单验证的功能,通过 rules 属性传入约定的验
| clearValidate | 移除表单项的校验结果 | - |
| resetFields | 对整个表单进行重置,将所有字段值重置为初始值并移除校验结果 | - |

## Form Events

| 事件名称 | 说明 | 回调参数 |
| -------- | -------------------- | --------------- |
| submit | 表单原生提交事件触发 | (event) => void |

## Form-Item Attributes

| 属性 | 说明 | 类型 | 默认值 |
Expand Down
7 changes: 7 additions & 0 deletions docs/.vitepress/components/input/event.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<FInput placeholder="请输入" @keydown="keyDown"></FInput>
Input事件
<FInput placeholder="请输入" @input="inputChange"></FInput>
Enter事件
<FInput placeholder="请输入" @keyup.enter="keyupEnter"></FInput>
</FSpace>
</template>

Expand All @@ -24,10 +26,15 @@ export default {
console.log('inputChange', e);
};
const keyupEnter = (e) => {
console.log('keyupEnter', e);
};
return {
textChange,
keyDown,
inputChange,
keyupEnter,
};
},
};
Expand Down
2 changes: 1 addition & 1 deletion docs/.vitepress/components/tag/edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
v-model="dynamicTags.state.inputValue"
class="input-tag"
size="small"
@blur="dynamicTags.handleInputConfirm"
@change="dynamicTags.handleInputConfirm"
>
</FInput>
<FButton v-else class="button-tag" @click="dynamicTags.showInput">
Expand Down
2 changes: 1 addition & 1 deletion docs/.vitepress/components/tag/withForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
v-model="dynamicTags.state.inputValue"
class="input-tag"
size="small"
@blur="dynamicTags.handleInputConfirm"
@change="dynamicTags.handleInputConfirm"
>
</FInput>
<FButton
Expand Down

0 comments on commit 5a566fa

Please sign in to comment.