`;
-exports[`EventAction:dialog args 7`] = `
+exports[`2. EventAction:dialog 7`] = `
{
+test('1. EventAction:dialog args', async () => {
const notify = jest.fn();
const {getByText, container}: any = render(
amisRender(
@@ -220,7 +220,7 @@ test('EventAction:dialog args', async () => {
expect(container).toMatchSnapshot();
}, 7000);
-test('EventAction:dialog', async () => {
+test('2. EventAction:dialog', async () => {
const notify = jest.fn();
const {getByText, container}: any = render(
amisRender(
@@ -433,7 +433,7 @@ test('EventAction:dialog', async () => {
expect(container).toMatchSnapshot();
}, 7000);
-test('EventAction:dialog data', async () => {
+test('3. EventAction:dialog data', async () => {
const {getByText, container}: any = render(
amisRender(
{
@@ -490,7 +490,7 @@ test('EventAction:dialog data', async () => {
});
}, 7000);
-test('EventAction:dialog data2', async () => {
+test('4. EventAction:dialog data2', async () => {
const {getByText, container}: any = render(
amisRender(
{
@@ -639,3 +639,77 @@ test('EventAction:dialog data2', async () => {
// // );
// // expect(confirm.mock.calls[0][1]).toEqual('操作确认');
// // });
+
+test('5. EventAction:dialog formitem without form', async () => {
+ const onAction = jest.fn();
+ const {getByText, container}: any = render(
+ amisRender(
+ {
+ type: 'page',
+ body: [
+ {
+ type: 'button',
+ label: 'Dialog',
+ onEvent: {
+ click: {
+ actions: [
+ {
+ actionType: 'dialog',
+ dialog: {
+ title: '表单页面',
+ body: [
+ {
+ label: 'A',
+ type: 'input-text',
+ name: 'a'
+ },
+ {
+ label: 'B',
+ type: 'input-text',
+ name: 'b'
+ }
+ ],
+ onEvent: {
+ confirm: {
+ actions: [
+ {
+ actionType: 'custom',
+ script: onAction
+ }
+ ]
+ }
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ ]
+ },
+ {},
+ makeEnv({
+ getModalContainer: () => container
+ })
+ )
+ );
+
+ const button = getByText('Dialog');
+ fireEvent.click(button);
+ await wait(200);
+
+ fireEvent.change(container.querySelector('[name="a"]')!, {
+ target: {value: '1'}
+ });
+
+ await wait(200);
+ fireEvent.change(container.querySelector('[name="b"]')!, {
+ target: {value: '2'}
+ });
+
+ await wait(200);
+ fireEvent.click(getByText('确认'));
+ await wait(300);
+ expect(onAction).toHaveBeenCalled();
+ expect(onAction.mock.calls[0][2].data).toMatchObject({a: '1', b: '2'});
+});
diff --git a/packages/amis/src/renderers/Dialog.tsx b/packages/amis/src/renderers/Dialog.tsx
index 08dd5736e..46311f1e2 100644
--- a/packages/amis/src/renderers/Dialog.tsx
+++ b/packages/amis/src/renderers/Dialog.tsx
@@ -1,5 +1,10 @@
import React from 'react';
-import {ScopedContext, IScopedContext, filterTarget} from 'amis-core';
+import {
+ ScopedContext,
+ IScopedContext,
+ filterTarget,
+ setVariable
+} from 'amis-core';
import {Renderer, RendererProps} from 'amis-core';
import {SchemaNode, Schema, ActionObject} from 'amis-core';
import {filter} from 'amis-core';
@@ -397,9 +402,11 @@ export default class Dialog extends React.Component {
// 如果 dialog 里面不放 form,而是直接放表单项就会进到这里来。
if (typeof name === 'string') {
- data = {
- [name]: data
+ const mergedData = {
+ ...store.form
};
+ setVariable(mergedData, name, data);
+ data = mergedData;
}
store.setFormData(data);