Skip to content

Commit

Permalink
fix: 修复 inputTable 单元中容器内表单项是否可获取父级数据逻辑异常问题 Close: baidu#9520 (baidu#…
Browse files Browse the repository at this point in the history
  • Loading branch information
2betop committed Feb 29, 2024
1 parent f155bee commit 134ce72
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/amis-core/src/renderers/wrapControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ export function wrapControl<

setInitialValue(value: any) {
const model = this.model!;
const {formStore: form, canAccessSuperData, data} = this.props;
const {formStore: form, data, canAccessSuperData} = this.props;
const isExp = isExpression(value);

if (isExp) {
Expand Down
72 changes: 72 additions & 0 deletions packages/amis/__tests__/renderers/Form/inputTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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', '']);
});

0 comments on commit 134ce72

Please sign in to comment.