Skip to content

I cannot use text input field in blockly to set a dynamic dropdown #4732

@victormorcam

Description

@victormorcam

I want to build a block that searches in a list the input text value ad display the results in the dropdown dynamically (using blockly).

This is what I am building but I am not able to get and use the text input value:

{
        "type": "search",
        "message0": "%1 %2",
        "args0": [
          {
            "type": "field_input",
            "name": "input1",
            "text": "whatever",
          },
          {
            "type": "input_dummy",
            "name": "INPUT"
          }
        ],
      "extensions": ["dynamic_menu_extension"],
      },
  Blockly.Extensions.register('dynamic_menu_extension',
  function() {
    this.getInput('INPUT')
      .appendField(new Blockly.FieldDropdown(
        function() {
          var options = [];
          Blockly.JavaScript['search'] = function(block) {
            var searchVal = block.getFieldValue('input1');
            return searchVal;}
          for (var i=0 ; i < list.length ; i++)
        {
             if (list[i] == searchVal) {
                options.push([list[i],list[i]]);
            }
        }
          return options;
        }), 'whatever1');
  });

It works as if the input text field was not defined.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions