Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
victormorcam opened this issue Mar 25, 2021 · 1 comment
Closed

Comments

@victormorcam
Copy link

victormorcam commented Mar 25, 2021

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.

@moniika moniika added the issue: triage Issues awaiting triage by a Blockly team member label Mar 26, 2021
@alschmiedt
Copy link
Contributor

Hello!

In order to get the text for the input field you can do something like below:
var searchValue = this.getInput('INPUT').fieldRow[0].getValue();

If you have any more questions please ask them on the forum. This keeps our github issues clean and gives you a chance to get help from other developers.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants