slackapi / java-slack-sdk

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

Radio Button showing "Please complete this required field." #1120

Closed prateek-narsinghani closed 1 year ago

prateek-narsinghani commented 1 year ago

I am trying to build a form using slack java sdk and want to use radio button. When I try to hardcode the option of radio button everything works as expected but when I am using values from a java object, the last option is selected by default and doesn't let me submit the form. This works ok:

blocks.add(input(input -> input
                        .element(radioButtons(r -> r.options(asOptions(
                                option(markdownText("Good"), "good"),
                                option(markdownText("Bad"), "bad")
                        ))))
                        .label(plainText(b -> b.text(field.getTitle())))
                        .blockId(blockId)));

But this doesn't:

blocks.add(input(input -> input
                        .element(SlackUtil.toRadioButton(choices))
                        .label(plainText(b -> b.text(field.getTitle())))
                        .blockId(blockId)));
public static RadioButtonsElement toRadioButton(List<Choice> choices) {
        List<OptionObject> optionObjects = new ArrayList<>();
        for(Choice choice : choices){
            OptionObject opt = option(plainText(choice.getLabel()), choice.getValue());
            optionObjects.add(opt);
        }
        return radioButtons(r ->r.options(optionObjects));
    }
@Data
@Builder
public class Choice {
    private String id;
    private String ref;
    private String label;
    private String value;
}
seratch commented 1 year ago

Hi @prateek-narsinghani, thanks for asking the question!

I cannot guess anything with given information. I'd suggest enabling slf4j's debug level logging for your app. With that, you can see the whole payload that your API call sends. Refer to https://slack.dev/java-slack-sdk/guides/bolt-basics#use-logger for learning how to change the log level.

I hope this helps!

prateek-narsinghani commented 1 year ago

Hi @seratch, thank you for such an early response. Viewing the payload helped me debug my issue. Thanks!

prateek-narsinghani commented 1 year ago

Hi @seratch, I am new to slack app development and was going through the repository to understand. Can you help me clarify a doubt? In the file ModalsTest.java there are two app.viewSubmission for callback id "meeting-arrangement", can you help me understand how they differ? I tried locally and the second block gets called every time. https://github.com/slackapi/java-slack-sdk/blob/main/bolt/src/test/java/test_locally/docs/ModalsTest.java#L116

seratch commented 1 year ago

@prateek-narsinghani The unit tests might be confusing for you, but it just verifies compilation. So, they are not great as working examples for you. You can register only one listener for a callback_id. Is everything clear now? If yes, would you mind closing this issue?

prateek-narsinghani commented 1 year ago

got it, thanks for clearing!