How to Refresh Options in Dynamic Dropdown

125 views
Skip to first unread message

Jason Morris

unread,
Feb 9, 2023, 7:06:43 PM2/9/23
to Blockly
What is the canonical way to force a dynamic dropdown to refresh its options in the workspace?

I know how to set an event listener, and check to see if that event is likely to impact on the list returned by the option generator function... I just don't know how to force that function to be re-run and the block updated. I'm looking for something like 

block.getField('dropdown_name').refreshOptions();

Thanks in advance,

J

Maribeth Bottorff

unread,
Feb 9, 2023, 8:52:55 PM2/9/23
to Blockly
Hello,

I believe I've answered your specific question in your other thread: https://groups.google.com/g/blockly/c/STIbpWetb88

For anyone else reading, dynamic dropdowns work by calling the provided function every time a dropdown is opened. For this to work, you need to pass in a function for Blockly to call that generates the options. Ensure that you aren't calling the function and passing in the results instead, as that would be a static dropdown. Read more about dynamic dropdowns here.

Maribeth

Reply all
Reply to author
Forward
0 new messages