From 18852fc82a898b907d9ad6ea14de9b324406fd00 Mon Sep 17 00:00:00 2001 From: liaoxuezhi Date: Wed, 3 Jul 2019 16:15:48 +0800 Subject: [PATCH] =?UTF-8?q?form=20=E6=94=AF=E6=8C=81=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/renderers.md | 1 + examples/components/Form/Validation.jsx | 5 ++++- src/renderers/Form/index.tsx | 6 ++++-- src/store/form.ts | 4 ++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/renderers.md b/docs/renderers.md index 2ca94dc52..5b3038ceb 100644 --- a/docs/renderers.md +++ b/docs/renderers.md @@ -74,6 +74,7 @@ amis 页面是通过 JSON 配置出来的,是由一个一个渲染模型组成 - [Chart](./renderers/Chart.md): 图表渲染器 - [Collapse](./renderers/Collapse.md): 折叠器 - [Carousel](./renderers/Carousel.md): 轮播图 +- [Alert](./renderers/Alert.md): 提示框 - [Audio](./renderers/Audio.md): 音频播放器 - [Video](./renderers/Video.md): 视频播放器 - [Table](./renderers/Table.md): 表格展示 diff --git a/examples/components/Form/Validation.jsx b/examples/components/Form/Validation.jsx index 41acee883..3b69614b6 100644 --- a/examples/components/Form/Validation.jsx +++ b/examples/components/Form/Validation.jsx @@ -1,11 +1,14 @@ export default { $schema: "https://houtai.baidu.com/v2/schemas/page.json#", title: "表单验证示例", - toolbar: "文档", + toolbar: "文档", body: [ { type: "form", autoFocus: false, + messages: { + 'validateFailed': '请仔细检查表单规则,部分表单项没通过验证' + }, title: "表单", actions: [ { diff --git a/src/renderers/Form/index.tsx b/src/renderers/Form/index.tsx index 779601cfa..68a069754 100644 --- a/src/renderers/Form/index.tsx +++ b/src/renderers/Form/index.tsx @@ -100,6 +100,7 @@ export interface FormProps extends RendererProps, FormSchema { fetchFailed?: string; saveSuccess?: string; saveFailed?: string; + validateFailed?: string; }; } @@ -398,10 +399,11 @@ export default class Form extends React.Component { submit(fn?:(values:object) => Promise):Promise { const { - store + store, + messages } = this.props; - return store.submit(fn, this.hooks['validate' || []]); + return store.submit(fn, this.hooks['validate' || []], messages && messages.validateFailed); } reset() { diff --git a/src/store/form.ts b/src/store/form.ts index 356b2af31..942610d4b 100644 --- a/src/store/form.ts +++ b/src/store/form.ts @@ -256,7 +256,7 @@ export const FormStore = ServiceStore } }); - const submit:(fn?:(values:object) => Promise, hooks?: Array<() => Promise>) => Promise = flow(function *submit(fn:any, hooks?: Array<() => Promise>) { + const submit:(fn?:(values:object) => Promise, hooks?: Array<() => Promise>, failedMessage?: string) => Promise = flow(function *submit(fn:any, hooks?: Array<() => Promise>, failedMessage?: string) { self.submited = true; self.submiting = true; @@ -264,7 +264,7 @@ export const FormStore = ServiceStore let valid = yield validate(hooks); if (!valid) { - (getRoot(self) as IRendererStore).notify('error', '表单验证失败,请仔细检查'); + (getRoot(self) as IRendererStore).notify('error', failedMessage || '表单验证失败,请仔细检查'); throw new Error('验证失败'); }