mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:48:13 +08:00
chore: 表单报错信息中增加所有表单项的报错信息 (#2357)
* chore: 表单报错信息中增加所有表单项的报错信息 * 修单元测试报错
This commit is contained in:
parent
73ac02f803
commit
9144176c6e
@ -60,7 +60,10 @@ test('Renderer:FormItem:validateApi:success', async () => {
|
||||
expect(onSubmit).not.toHaveBeenCalled();
|
||||
|
||||
await wait(100);
|
||||
expect(notify).toHaveBeenCalledWith('error', '依赖的部分字段没有通过验证');
|
||||
expect(notify).toHaveBeenCalledWith(
|
||||
'error',
|
||||
'依赖的部分字段没有通过验证\na: 这是必填项'
|
||||
);
|
||||
|
||||
const input = container.querySelector('input[name=a]');
|
||||
expect(input).toBeTruthy();
|
||||
@ -129,7 +132,10 @@ test('Renderer:FormItem:validateApi:failed', async () => {
|
||||
expect(onSubmit).not.toHaveBeenCalled();
|
||||
|
||||
await wait(100);
|
||||
expect(notify).toHaveBeenCalledWith('error', '依赖的部分字段没有通过验证');
|
||||
expect(notify).toHaveBeenCalledWith(
|
||||
'error',
|
||||
'依赖的部分字段没有通过验证\na: 这是必填项'
|
||||
);
|
||||
|
||||
const input = container.querySelector('input[name=a]');
|
||||
expect(input).toBeTruthy();
|
||||
|
@ -106,7 +106,10 @@ test('Renderer:Form:valdiate', async () => {
|
||||
expect(onSubmit).not.toHaveBeenCalled();
|
||||
|
||||
await wait(100);
|
||||
expect(notify).toHaveBeenCalledWith('error', '依赖的部分字段没有通过验证');
|
||||
expect(notify).toHaveBeenCalledWith(
|
||||
'error',
|
||||
'依赖的部分字段没有通过验证\na: 这是必填项'
|
||||
);
|
||||
|
||||
const input = container.querySelector('input[name=a]');
|
||||
expect(input).toBeTruthy();
|
||||
@ -228,7 +231,10 @@ test('Renderer:Form:onValidate', async () => {
|
||||
expect(onValidate.mock.calls[0][0]).toMatchSnapshot();
|
||||
|
||||
await wait(100);
|
||||
expect(notify).toHaveBeenCalledWith('error', '依赖的部分字段没有通过验证');
|
||||
expect(notify).toHaveBeenCalledWith(
|
||||
'error',
|
||||
'依赖的部分字段没有通过验证\na: a is wrong\nb: b is wrong\nb: b is wrong 2'
|
||||
);
|
||||
|
||||
fireEvent.click(getByText('Submit'));
|
||||
await wait(100);
|
||||
|
@ -459,9 +459,18 @@ export const FormStore = ServiceStore.named('FormStore')
|
||||
)) ||
|
||||
self.restError.length
|
||||
) {
|
||||
const msg = failedMessage ?? self.__('Form.validateFailed');
|
||||
let msg = failedMessage ?? self.__('Form.validateFailed');
|
||||
// 同时也列出所有表单项报错,方便在很长的表单中知道是哪个字段的问题
|
||||
failedMessage ??
|
||||
self.items.forEach(item => {
|
||||
item.errorData.forEach(errorData => {
|
||||
msg = `${msg}\n${item.name}: ${errorData.msg}`;
|
||||
});
|
||||
});
|
||||
|
||||
msg && getEnv(self).notify('error', msg);
|
||||
throw new Error(self.__('Form.validateFailed'));
|
||||
|
||||
throw new Error(msg);
|
||||
}
|
||||
|
||||
if (fn) {
|
||||
|
Loading…
Reference in New Issue
Block a user