amis2/examples/components/EventAction/cmpt-event-action/FormEvent.jsx
hsm-lv f1b383608b
fix:修复事件动作对禁用状态控制失效问题&更新文档示例 (#4278)
* fix:修复事件动作对禁用状态控制失效问题&更新文档示例

* fix:修复事件动作对禁用状态控制失效问题

* fix:修复事件动作对禁用状态控制失效问题
2022-05-10 19:31:20 +08:00

292 lines
6.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export default {
type: 'page',
title: 'form组件支持动作示例',
regions: ['body', 'toolbar', 'header'],
body: [
{
type: 'action',
label: '清空表单',
level: 'primary',
className: 'mr-3 mb-3',
onEvent: {
click: {
actions: [
{
componentId: 'form-action-receiver',
actionType: 'clear'
}
]
}
}
},
{
type: 'action',
label: '重置表单',
level: 'primary',
className: 'mr-3 mb-3',
onEvent: {
click: {
actions: [
{
actionType: 'reset',
componentId: 'form-action-receiver'
}
]
}
}
},
{
type: 'action',
label: '校验表单',
level: 'primary',
className: 'mr-3 mb-3',
onEvent: {
click: {
actions: [
{
actionType: 'validate',
componentId: 'form-action-receiver'
}
]
}
}
},
{
type: 'action',
label: '重新加载表单组件',
level: 'primary',
className: 'mr-3 mb-3',
onEvent: {
click: {
actions: [
{
actionType: 'reload',
componentId: 'form-action-receiver'
}
]
}
}
},
{
type: 'action',
label: '提交表单',
level: 'primary',
className: 'mr-3 mb-3',
onEvent: {
click: {
actions: [
{
actionType: 'submit',
componentId: 'form-action-receiver'
}
]
}
}
},
{
name: 'form-action-receiver',
id: 'form-action-receiver',
title: '表单用于接收上面按钮的动作派发form本身的事件',
type: 'form',
debug: true,
api: '/api/mock2/form/saveForm',
data: {
data1: '初始化数据1',
data2: '初始化数据2'
},
initApi:
'https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/form/initData',
body: [
{
type: 'input-text',
name: 'name',
label: '姓名',
required: true,
validateOnChange: true
},
{
type: 'input-text',
name: 'email',
label: '邮箱',
required: true,
validateOnChange: true,
validations: {
isEmail: true
}
}
],
onEvent: {
change: {
actions: [
{
actionType: 'toast',
args: {
msg: '表单值变化:${event.data|json}'
}
}
]
},
inited: {
actions: [
{
actionType: 'toast',
args: {
msg: '表单初始化完成:${event.data|json}'
}
}
]
},
formItemValidateSucc: {
actions: [
{
actionType: 'toast',
args: {
msg: '表单项校验成功:${event.data|json}'
}
}
]
},
formItemValidateError: {
actions: [
{
actionType: 'toast',
args: {
msg: '表单项校验失败:${event.data|json}'
}
}
]
},
validateSucc: {
actions: [
{
actionType: 'toast',
args: {
msg: '表单校验成功:${event.data|json}'
}
}
]
},
validateError: {
actions: [
{
actionType: 'toast',
args: {
msg: '表单校验失败:${event.data|json}'
}
}
]
},
submitSucc: {
actions: [
{
actionType: 'toast',
args: {
msg: '提交成功:${event.data|json}'
}
}
]
},
submitSucc: {
actions: [
{
actionType: 'toast',
args: {
msg: '提交失败:${event.data|json}'
}
}
]
}
}
},
{
type: 'form',
debug: true,
api: '/api/mock2/form/saveForm',
title: '表单派发formItem的校验事件',
data: {
data1: '初始化数据1',
data2: '初始化数据2'
},
initApi:
'https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/form/initData',
body: [
{
type: 'input-text',
name: 'name',
label: '姓名',
required: true,
validateOnChange: true
},
{
type: 'input-text',
name: 'email',
label: '邮箱',
required: true,
validateOnChange: true,
validations: {
isEmail: true
}
}
],
onEvent: {
formItemValidateSucc: {
actions: [
{
actionType: 'toast',
args: {
msg: '表单项校验成功:${event.data|json}'
}
}
]
},
formItemValidateError: {
actions: [
{
actionType: 'toast',
args: {
msg: '表单项校验失败:${event.data|json}'
}
}
]
}
}
},
{
type: 'form',
debug: true,
title: "表单提交表单无target无api只触发提交成功事件",
body: [
{
type: 'input-text',
name: 'name',
label: '姓名',
required: true,
validateOnChange: true
},
{
type: 'input-text',
name: 'email',
label: '邮箱',
required: true,
validateOnChange: true,
validations: {
isEmail: true
}
}
],
onEvent: {
submitSucc: {
actions: [
{
actionType: 'toast',
args: {
msg: '提交成功:${event.data|json}'
}
}
]
},
}
}
]
};