You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Slack API时能否将模态框中的输入项设置为非必填?

Slack 的 Block Kit 中,input 类型的块默认是必填字段,你只需要在输入块的顶层配置中添加 optional 参数并设为 true 即可将该选择器设为非必填。dispatch_action 参数仅用于控制用户操作该字段时是否触发交互事件,和字段是否必填无关。

修改后的配置代码如下:

[
    'type' => 'input',
    'dispatch_action' => false,
    'optional' => true, // 新增该配置项即可实现非必填效果
    'label' => [
    'type' => 'plain_text',
        'text' => 'Choose an option (or not)',
    ],
    'element' => [
        'type' => 'static_select',
        'placeholder' => [
            'type' => 'plain_text',
            'text' => 'Choose an option',
        ],
        'options' => array_map(static function($data) {
            return [
                'text' => [
                    'type' => 'plain_text',
                    'text' => $data->name,
                ],
                'value' => (string) $data->id,
            ];
        }, $dataValues),
    ],
],

添加该配置后字段前的必填星标会消失,用户提交模态框时无需选中选项也可以正常提交。

内容的提问来源于stack exchange,提问作者jiboulex

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 04:54:06