From 11f32a9f934330c34588ab75ffe224d851869e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=A4=9A=E7=9B=8A?= Date: Mon, 12 Apr 2021 23:11:31 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E8=A1=A8=E5=8D=95=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=A6=81=E7=94=A8=E5=9B=9E=E8=BD=A6=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=20(#1787)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh-CN/components/form/index.md | 27 +++++++++++++++++++++++++-- src/renderers/Form/index.tsx | 11 +++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/docs/zh-CN/components/form/index.md b/docs/zh-CN/components/form/index.md index c2857c8d4..5135d8548 100755 --- a/docs/zh-CN/components/form/index.md +++ b/docs/zh-CN/components/form/index.md @@ -431,8 +431,6 @@ Form 默认会在底部渲染一个提交按钮,用于执行表单的提交行 > 表单项的 value 是不支持表达式,所以不要尝试用 `value: "${xxx}"` 来关联数据。 - - ### 轮询初始化请求 Form 支持轮询初始化接口,步骤如下: @@ -918,6 +916,30 @@ Form 支持轮询初始化接口,步骤如下: 如果想提交成功后,清空该缓存,则配置`"clearPersistDataAfterSubmit": true` +## 禁用回车提交 + +表单默认情况下回车就会提交,如果想阻止这个行为,可以加上 `preventEnterSubmit` 配置项。 + +```schema: scope="body" +{ + "type": "form", + "api": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/form/saveForm", + "preventEnterSubmit": true, + "controls": [ + { + "type": "text", + "name": "name", + "label": "姓名:" + }, + { + "name": "email", + "type": "email", + "label": "邮箱:" + } + ] +} +``` + ## 属性表 | 属性名 | 类型 | 默认值 | 说明 | @@ -963,5 +985,6 @@ Form 支持轮询初始化接口,步骤如下: | canAccessSuperData | `boolean` | `true` | 指定是否可以自动获取上层的数据并映射到表单项上 | | persistData | `boolean` | `true` | 指定表单是否开启本地缓存 | | clearPersistDataAfterSubmit | `boolean` | `true` | 指定表单提交成功后是否清除本地缓存 | +| preventEnterSubmit | `boolean` | `false` | 禁用回车提交表单 | | trimValues | `boolean` | `false` | trim 当前表单项的每一个值 | | promptPageLeave | `boolean` | `false` | form 还没保存,即将离开页面前是否弹框确认。 | diff --git a/src/renderers/Form/index.tsx b/src/renderers/Form/index.tsx index aec6293d7..04648a5e8 100644 --- a/src/renderers/Form/index.tsx +++ b/src/renderers/Form/index.tsx @@ -287,6 +287,11 @@ export interface FormSchema extends BaseSchema { rule: string; message: string; }>; + + /** + * 禁用回车提交 + */ + preventEnterSubmit?: boolean; } export type FormGroup = FormSchema & { @@ -818,7 +823,13 @@ export default class Form extends React.Component { } handleFormSubmit(e: React.UIEvent) { + const {preventEnterSubmit} = this.props; + e.preventDefault(); + if (preventEnterSubmit) { + return false; + } + return this.handleAction( e, {