fix:表单使用增加两个限制条件 (#2562)

Co-authored-by: dqc <qianchuan.deng@gmail.com>
This commit is contained in:
qianchuan 2021-09-28 23:07:52 +08:00 committed by GitHub
parent e1c9f44fa5
commit 78233c14eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 77 additions and 118 deletions

View File

@ -195,123 +195,65 @@ exports[`factory:definitions 1`] = `
class="cxd-Combo-itemInner" class="cxd-Combo-itemInner"
> >
<div <div
class="cxd-Form cxd-Form--normal cxd-Combo-form" class="cxd-Alert cxd-Alert--danger"
novalidate=""
> >
<input <p>
style="display: none;" Error: 不允许在表单及表单按钮组中直接嵌套表单
type="submit" </p>
/> <p>
<div Path:
class="cxd-Form-item cxd-Form-item--normal" page/body/0/form/1/combo/multiple/0/form
data-role="form-item" </p>
> <pre>
<label <code>
class="cxd-Form-label" {
> "type": "form",
<span> "body": [
<span {
class="cxd-TplField" "label": "combo 1",
> "type": "input-text",
<span> "name": "key"
combo 1 },
</span> {
</span> "type": "input-text",
</span> "name": "value",
</label> "value": "ref value",
<div "remark": "通过&lt;code&gt;\\\\$ref&lt;/code&gt;引入的组件",
class="cxd-Form-control cxd-TextControl" "label": "combo 2"
> },
<div {
class="cxd-TextControl-input" "type": "combo",
> "multiple": true,
<input "multiLine": true,
autocomplete="off" "remark": "&lt;code&gt;combo&lt;/code&gt;中的子项引入自身,实现嵌套的效果",
name="key" "controls": [
placeholder="" {
size="10" "label": "combo 1",
type="text" "type": "text",
value="" "name": "key"
/> },
</div> {
</div> "label": "combo 2",
</div> "name": "value",
<div "$ref": "aa"
class="cxd-Form-item cxd-Form-item--normal" },
data-role="form-item" {
> "name": "children",
<label "label": "children",
class="cxd-Form-label" "$ref": "bb"
> }
<span> ],
<span "name": "children",
class="cxd-TplField" "label": "children"
> }
<span> ],
combo 2 "wrapperComponent": "div",
</span> "wrapWithPanel": false,
</span> "mode": "normal",
</span> "className": "cxd-Combo-form"
</label> }
<div </code>
class="cxd-Form-control cxd-TextControl" </pre>
>
<div
class="cxd-TextControl-input"
>
<input
autocomplete="off"
name="value"
placeholder=""
size="10"
type="text"
value="ref value"
/>
</div>
</div>
<div
class="cxd-Remark cxd-Form-remark"
>
<span
class="cxd-Remark-icon"
>
<icon-mock
classname=" icon-warning-mark"
icon="warning-mark"
/>
</span>
</div>
</div>
<div
class="cxd-Form-item cxd-Form-item--normal"
data-role="form-item"
>
<label
class="cxd-Form-label"
>
<span>
<span
class="cxd-TplField"
>
<span>
children
</span>
</span>
</span>
</label>
<div
class="cxd-Remark cxd-Form-remark"
>
<span
class="cxd-Remark-icon"
>
<icon-mock
classname=" icon-warning-mark"
icon="warning-mark"
/>
</span>
</div>
</div>
</div> </div>
</div> </div>
<a <a

BIN
dump.rdb Normal file

Binary file not shown.

View File

@ -54,6 +54,7 @@ import {
import {ActionSchema} from '../Action'; import {ActionSchema} from '../Action';
import {ButtonGroupControlSchema} from './ButtonGroupSelect'; import {ButtonGroupControlSchema} from './ButtonGroupSelect';
import {DialogSchemaBase} from '../Dialog'; import {DialogSchemaBase} from '../Dialog';
import Alert from '../../components/Alert2';
export interface FormSchemaHorizontal { export interface FormSchemaHorizontal {
left?: number; left?: number;
@ -1493,6 +1494,8 @@ export default class Form extends React.Component<FormProps, object> {
render() { render() {
const { const {
$path,
$schema,
wrapWithPanel, wrapWithPanel,
render, render,
title, title,
@ -1507,7 +1510,8 @@ export default class Form extends React.Component<FormProps, object> {
affixFooter, affixFooter,
lazyLoad, lazyLoad,
translate: __, translate: __,
footer footer,
formStore
} = this.props; } = this.props;
// trace(true); // trace(true);
@ -1515,7 +1519,20 @@ export default class Form extends React.Component<FormProps, object> {
let body: JSX.Element = this.renderBody(); let body: JSX.Element = this.renderBody();
if (wrapWithPanel) { // 表单组件限制
const isFormInFormActions: boolean = /panel\/action\/form$/.test($path);
// props有formStore 说明是嵌套表单 || 不允许在表单的按钮组中再直接套表单
if (formStore || isFormInFormActions) {
body = (
<Alert level="danger">
<p>Error: </p>
<p>Path: {$path}</p>
<pre>
<code>{JSON.stringify($schema, null, 2)}</code>
</pre>
</Alert>
);
} else if (wrapWithPanel) {
body = render( body = render(
'body', 'body',
{ {