We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

How can I create two associated dropdown lists in one block

Home Forums General Questions How can I create two associated dropdown lists in one block

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #50610
    aqiang
    Customer

    Hi!

    Is it possible to create two associated dropdown lists in one block, so when user select item in first list, second list is generated according to this item.
    The same question can be found on the Internet about block. The answer is about extensions, but there is no relevant content in the verge plug-in. Can you provide such a minimum case

    Thank you

    #50620
    aqiang
    Customer

    The following is my wrong attempt to find out the problem

    <script>
    
        function template(block) {
            var color1_ops = [
                ['green', 'GREEN'],
                ['yellow', 'YELLOW'],
                ['red', 'RED'],
            ];
            block.Extensions = ["color_pair2"];//?
            block.appendDummyInput()
                .appendField(new Blockly.FieldDropdown(color1_ops), 'COLOR1');
    
            Blockly.Extensions.register('color_pair2',//?
                function () {
                    var input = this.inputList[0];
                    var color1 = this.getField('COLOR1');
                    var color2 = new Blockly.FieldDropdown(function () {
                        // Generate the drop down to match color1
                        return [[color1.getText() + ', again', color1.getValue()],
                        ['Black', 'BLACK'],
                        ['White', 'WHITE']];
                    });
                    input.appendField(color2);
                    this.setOnChange(function () {
                        if (color2.getValue() != 'BLACK' && color2.getValue() != 'WHITE') {
                            color2.setValue(color1.getValue());
                            color2.setText(color1.getText() + ', again');
                        }
                    })
                });
    
        }
    
    </script>
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.