fix: 修复 inputTable 单元中容器内表单项是否可获取父级数据逻辑异常问题 Close: #9520 (#9608)

This commit is contained in:
liaoxuezhi 2024-02-29 15:39:50 +08:00 committed by GitHub
parent f155bee870
commit 134ce7280e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 73 additions and 1 deletions

View File

@ -468,7 +468,7 @@ export function wrapControl<
setInitialValue(value: any) { setInitialValue(value: any) {
const model = this.model!; const model = this.model!;
const {formStore: form, canAccessSuperData, data} = this.props; const {formStore: form, data, canAccessSuperData} = this.props;
const isExp = isExpression(value); const isExp = isExpression(value);
if (isExp) { if (isExp) {

View File

@ -947,3 +947,75 @@ test('Renderer:input-table autoFill', async () => {
] ]
}); });
}); });
// 对应 github issue: https://github.com/baidu/amis/issues/9520
test('Renderer:input-table canAccessSuperData', async () => {
const onSubmit = jest.fn();
const {container} = render(
amisRender(
{
type: 'page',
body: {
type: 'form',
data: {
a: 'xxx',
table: [
{
a: 'a1',
b: 'b1'
}
]
},
api: '/amis/api/mock2/form/saveForm',
body: [
{
showIndex: true,
type: 'input-table',
name: 'table',
addable: true,
needConfirm: true,
columns: [
{
name: 'a',
label: 'A',
type: 'wrapper',
body: [
{
name: 'a',
label: false,
type: 'input-text'
}
]
},
{
name: 'b',
label: 'B',
type: 'input-text'
}
]
}
]
}
},
{},
makeEnv({})
)
);
await wait(200);
const addBtn = container.querySelector('.cxd-OperationField button');
expect(addBtn).toBeInTheDocument();
fireEvent.click(addBtn!);
await wait(200);
const confrimBtn = container.querySelector('.cxd-OperationField button');
expect(confrimBtn).toBeInTheDocument();
fireEvent.click(confrimBtn!);
await wait(200);
const inputs = [].slice
.call(container.querySelectorAll('tbody td input[name="a"]'))
.map((td: any) => td.value);
expect(inputs).toEqual(['a1', '']);
});