fix: Form中嵌套容器后,容器中组件disabled失效问题 (#5473)

This commit is contained in:
RUNZE LU 2022-09-29 18:38:41 +08:00 committed by GitHub
parent 512a313fb1
commit b7f79c6102
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 10 deletions

View File

@ -218,7 +218,33 @@ order: 1
"label": "禁用",
"name": "text2",
"disabled": true
}
},
{
"type": "grid",
"columns": [
{
"body": [
{
"type": "input-text",
"label": "姓名",
"name": "name",
"value": "amis",
"disabled": true
}
]
},
{
"body": [
{
"type": "input-email",
"label": "邮箱",
"name": "email",
"disabled": true
}
]
}
]
},
]
}
```

View File

@ -16,7 +16,7 @@ import {ScopedContext} from './Scoped';
import {Schema, SchemaNode} from './types';
import {DebugWrapper} from './utils/debug';
import getExprProperties from './utils/filter-schema';
import {anyChanged, chainEvents, autobind, createObject} from './utils/helper';
import {anyChanged, chainEvents, autobind} from './utils/helper';
import {SimpleMap} from './utils/SimpleMap';
import {bindEvent, dispatchEvent, RendererEvent} from './utils/renderer-event';

View File

@ -1522,7 +1522,14 @@ export default class Form extends React.Component<FormProps, object> {
formLabelAlign: labelAlign !== 'left' ? 'right' : labelAlign,
formLabelWidth: labelWidth,
controlWidth,
disabled: disabled || (control as Schema).disabled || form.loading,
/**
* form.loading有为true时才下发disabled属性disbaled为false
* Form中包含容器类组件时disbaled继续下发至子组件SchemaRenderer中props.disabled覆盖schema.disabled
*/
disabled:
disabled ||
(control as Schema).disabled ||
(form.loading ? true : undefined),
btnDisabled: disabled || form.loading || form.validating,
onAction: this.handleAction,
onQuery: this.handleQuery,

View File

@ -1,13 +1,7 @@
import React from 'react';
import {FormHorizontal, Renderer, RendererProps} from 'amis-core';
import {Schema} from 'amis-core';
import pick from 'lodash/pick';
import {
BaseSchema,
SchemaClassName,
SchemaCollection,
SchemaObject
} from '../Schema';
import {BaseSchema, SchemaClassName, SchemaCollection} from '../Schema';
import {ucFirst} from 'amis-core';
import {Spinner} from 'amis-ui';