slackapi / java-slack-sdk

Slack Developer Kit (including Bolt for Java) for any JVM language
https://slack.dev/java-slack-sdk/
MIT License
571 stars 212 forks source link

Setting dropdown value based on another dropdown value #1221

Closed karishma21mahajan21 closed 11 months ago

karishma21mahajan21 commented 11 months ago

I am trying to set a static select dropdown value based on another static select value. I am able to dispatch an action on first static select dropdown selection. Able to set values for the second static select dropdown values as well. But even if i set initial option for second dropdown like below dropDownElement.setInitialOption(new val) Even though initial value is updated but initial option is still the older value selected.

InputBlock blockElement =  ... // block element fetched from "req.getPayload().getView()"

List<OptionObject> dropdownOptions = dropdown options;
StaticSelectElement dropdownElement = blockElement.getElement();

dropdownElement(dropdownOptions);
dropdownElement(dropdownOptions.get(0));

After preparing the new view on BlockActionHandler, I am updating the view with

ctx.client().viewsUpdate(r -> r
        .viewId(currentViewId)
        .hash(currentHash)
        .view(finalNewView) 
);
seratch commented 11 months ago

Hi @karishma21mahajan21, thanks for asking the question. However, I still don't understand what your question is. Could you share the modal UI you're trying to build? You can simulate it using Block Kit Builder and share the URL with us: https://app.slack.com/block-kit-builder

karishma21mahajan21 commented 11 months ago

Hi @seratch, PFB link: block-kit-builder

Payload: { "blocks": [ { "type": "input", "element": { "type": "static_select", "placeholder": { "type": "plain_text", "text": "Select an item", "emoji": true }, "options": [ { "text": { "type": "plain_text", "text": "*this is plain_text text*", "emoji": true }, "value": "value-0" }, { "text": { "type": "plain_text", "text": "*this is plain_text text*", "emoji": true }, "value": "value-1" }, { "text": { "type": "plain_text", "text": "*this is plain_text text*", "emoji": true }, "value": "value-2" } ], "action_id": "static_select-action" }, "label": { "type": "plain_text", "text": "Dropdown1", "emoji": true } }, { "type": "input", "element": { "type": "static_select", "placeholder": { "type": "plain_text", "text": "Select an item", "emoji": true }, "options": [ { "text": { "type": "plain_text", "text": "*this is plain_text text*", "emoji": true }, "value": "value-0" }, { "text": { "type": "plain_text", "text": "*this is plain_text text*", "emoji": true }, "value": "value-1" }, { "text": { "type": "plain_text", "text": "*this is plain_text text*", "emoji": true }, "value": "value-2" } ], "action_id": "static_select-action" }, "label": { "type": "plain_text", "text": "Dropdown2", "emoji": true } } ] }

I have 2 static dropdowns and values of dropdown 2 will change based on the value in dropdown 1. I am able to achieve that but only issue is the initial option/ default value for dropdown is not changing even if i set initial value for dropdown 2 in the BlockActionHandler

seratch commented 11 months ago

Thanks for your quick reply. It seems that your issue is the same with https://github.com/slackapi/bolt-js/issues/1920#issuecomment-1669627257 . Our team already escalated the issue to the server-side engineering teams, but it seems that it is not yet resolved. Please consider going with the workaround shared in the thread. We apologize for the inconvenience.