首页 > 解决方案 > Slack Bolt Python:如何使模式中的输入字段可选?

问题描述

我正在使用模态来收集数据。我通过以下代码打开了一个视图:

view = {
    "type": "modal",
    "title": {
        "type": "plain_text",
        "text": "My App",
        "emoji": True
    },
    "submit": {
        "type": "plain_text",
        "text": "Submit",
        "emoji": True
    },
    "close": {
        "type": "plain_text",
        "text": "Cancel",
        "emoji": True
    },
    "blocks": [
        {
            "type": "input",
            "element": {
                "type": "plain_text_input",
                "action_id": "plain_text_input-action"
            },
            "label": {
                "type": "plain_text",
                "text": "Please leave feedback here",
                "emoji": True
            }
        }
    ]
    }
slack_client.views_open(trigger_id=body['trigger_id'],view=view)

在此处输入图像描述

我想让输入文本可选,也就是说,即使用户将输入字段留空,他/她仍然可以提交模式。这可以实现吗?

标签: slackslack-apislack-block-kit

解决方案


您可以添加"optional": true为输入块的属性。

"blocks": [
        {
            "type": "input",

            "optional": true,

            "element": {
                "type": "plain_text_input",
                "action_id": "plain_text_input-action"
            },
            "label": {
                "type": "plain_text",
                "text": "Label",
                "emoji": true
            }
        }
    ]

推荐阅读