Bolt-js: Getting at selected options values from checkboxes

Created on 1 Nov 2020  路  4Comments  路  Source: slackapi/bolt-js

Why is there this intermediate random object name in between skills_selection and checkboxes? Why is there a dynamically named object there?

How am I supposed to get to selected_options when this value keeps changing on me? Is there some sort of ID I can put on the elements section somewhere to make this consistent?

const stateValues = view.state.values;

So looking at stateValues.skills_selection, Zn7v keeps changing. I end up having to do a hack which is bad: Object.values(stateValues.skills_selection)[0].selected_options

Screen Shot 2020-11-01 at 12 37 00 PM

{
  type: "input",
  block_id: "skills_selection",
  element: {
    type: "checkboxes",
    options: skillOptions
  },
  label: {
    type: "plain_text",
    text: "Please select your skills"
  }
}
question

All 4 comments

Hi @dschinkel -- you can add an action_id to the element object to reach this end. Doing so will result in a payload that looks like the following:

{
  skills_selection: {
    this_is_an_action_id: { type: 'checkboxes', selected_options: [Array] }
  }
}

As for why this is done, the generated key is simply a unique identifier for that particular element in the absence of one being specified by way of action_id.

thanks I'll give it a try.

Hey @dschinkel, just following up. Did the above suggestion resolve the issue? If so, I'd like to close this.

yes it worked fine thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

seblaz picture seblaz  路  4Comments

Falci picture Falci  路  5Comments

simonsayscode picture simonsayscode  路  3Comments

TK95 picture TK95  路  3Comments

jacklein picture jacklein  路  4Comments