slackslack-apislack-block-kit

Slack Bolt Python: how to make the input field in modal optional?


I'm using modal to collect data. I opened a view by the following code:

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)

enter image description here

I want to make the input text optional, that is, even though the user leaves the input field blank, he/she can still submit the modal. Can this be realized?


Solution

  • You can add "optional": true as property of the input block, not the text element.

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