jiboulex
jiboulex

Reputation: 3021

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

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 !

Upvotes: 8

Views: 5099

Answers (2)

Prof.
Prof.

Reputation: 1

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

Upvotes: 0

Suyash Gaur
Suyash Gaur

Reputation: 2881


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

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

Upvotes: 8

Related Questions