Files
Starlight_Lancher/.agents/skills/lark-im/references/card/components/form.md

2.2 KiB
Raw Blame History

表单容器 form

批量录入表单项后一次提交:用户在前端填写多个表单项,点击提交按钮后将所有值打包一次性回调到服务端。Card 2.0

最小示例

{
  "tag": "form",
  "name": "form_1",
  "elements": [
    { "tag": "input", "name": "reason", "required": true },
    {
      "tag": "button",
      "text": { "tag": "plain_text", "content": "提交" },
      "type": "primary",
      "form_action_type": "submit",
      "name": "Button_submit"
    }
  ]
}

字段

字段 必填 类型 默认 说明
tag String / 固定 form
name String / 表单容器唯一标识,卡片内全局唯一,用于识别提交数据归属
elements Element[] [] 子节点,支持除 tableform 外的所有组件
direction String vertical vertical / horizontal
horizontal_spacing/vertical_spacing String 8px/12px 间距枚举 small(4)/medium(8)/large(12)/extra_large(16) 或 [0,99]px
horizontal_align String left left/center/right
vertical_align String top top/center/bottom
padding/margin String 0 [-99,99]px支持单值/双值/四值写法
element_id String / 唯一标识,字母开头 ≤20 字符

子组件内嵌字段(交互组件嵌在 form 内时生效)

字段 必填 说明
name 表单内组件唯一标识,卡片全局唯一,否则提交失败
required 是否必填;为 true 且未填时点提交会本地拦截,不发起回调
form_action_type 是(按钮) submit(提交)/ reset(重置初始值);表单内按钮不用 behaviors

嵌套 / 易错点

  • form 不支持嵌套 tableform;且 form 本身只能放卡片根节点下,不能被其他组件嵌套。
  • form 内所有交互组件的 name 必须填且全局唯一,否则提交失败。
  • 表单内必须包含一个 form_action_type: submit 的按钮。
  • 回调来源:card.action.triggeraction.tag="button" + action.form_value(按组件 name 映射各字段值)。