Skip to content

Commit

Permalink
fix: 修复 inputTable 行确认时没有触发校验的问题 Close: baidu#9537
Browse files Browse the repository at this point in the history
  • Loading branch information
2betop committed Feb 18, 2024
1 parent 6ef0248 commit 0b57f07
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
63 changes: 63 additions & 0 deletions packages/amis/__tests__/renderers/Form/inputTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -809,3 +809,66 @@ test('Renderer:input-table formula', async () => {
]
});
});

// 对应 github issue: https://github.com/baidu/amis/issues/9537
test('Renderer:input-table item confirm validate', async () => {
const onSubmit = jest.fn();
const {container, findByRole, findByText} = render(
amisRender(
{
type: 'page',
body: {
type: 'form',
data: {
table: [
{
a: 'a1',
b: 'b1'
}
]
},
api: '/amis/api/mock2/form/saveForm',
body: [
{
showIndex: true,
type: 'input-table',
name: 'table',
addable: true,
columns: [
{
name: 'a',
label: 'A',
quickEdit: {
type: 'input-text',
required: true
}
},
{
name: 'b',
label: 'B'
}
],
needConfirm: true
}
]
}
},
{},
makeEnv({})
)
);

await wait(200);
const addBtn = container.querySelector('.cxd-OperationField button');
expect(addBtn).toBeInTheDocument();
fireEvent.click(addBtn!);

await wait(200);
const confirmBtn = container.querySelector('.cxd-OperationField button');
expect(confirmBtn).toBeInTheDocument();
fireEvent.click(confirmBtn!);

await wait(200);

expect(container.querySelector('.has-error--isRequired')).toBeInTheDocument();
});
4 changes: 3 additions & 1 deletion packages/amis/src/renderers/Form/InputTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,9 @@ export default class FormTable extends React.Component<TableProps, TableState> {
});

const results = await Promise.all(
validateForms.map(item => item.validate())
validateForms
.map(item => item.validate())
.concat(subFormItems.map(item => item.props.onValidate()))
);

// 有校验不通过的
Expand Down

0 comments on commit 0b57f07

Please sign in to comment.