Is it possible to make an input not required with Slack API?
Asked Answered
S

2

7

I'm building a Slack App feature with a modal and several inputs.

One of them is a static select with some options.

I would like to make it optionnal but it seems that there is no solution for that.

I tried to set dispatch_action to false but it is unrelated I believe.

Here is my input configuration :

[
    'type' => 'input',
    'dispatch_action' => false,
    '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),
    ],
],

I can't make this field not required

Thanks for your help !

Subjectify answered 13/10, 2021 at 10:29 Comment(0)
C
8


You can add "optional": true as property of input block.

'type' => 'input',
'optional': true,
'dispatch_action' => false,

Calvaria answered 13/10, 2021 at 12:7 Comment(3)
Thank you sir, I missed that config option !Subjectify
Thank you! Do you know where this is documented? I don't see it anywhere in the docs for block elementsZook
I couldn't find the specific documentation but if you check the example here, you can find it: api.slack.com/surfaces/modals/using#modal_response_urlCalvaria
S
0

If you are using any SDK like I was using go slack-sdk. I was able to do it like this :

 commentBlock := slack.NewInputBlock(
        blockID,
        slack.NewTextBlockObject(slack.PlainTextType, "Comment", false, false),
        slack.NewTextBlockObject(slack.PlainTextType, "Please provide a reason for your action", false, false),
        slack.NewPlainTextInputBlockElement(nil, fmt.Sprintf("%s_action", blockID)),
    )
    commentBlock.Optional = true
Submergible answered 6/5 at 10:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.