1

I am developing blockly and I need a dropdown which use image instead of text. My code is like this.

Blockly.Blocks['image_dropdown_test']={
    init: function(){
        var options = [
            [{'src': 'canada.svg', 'width': 50, 'height': 25, 'alt': 'Canada'}, 'CANADA']
            ]
        this.appendValueInput("fl").appendField("adsad").appendField(new Blockly.FieldDropdown(options), 'FLAG');
        this.setTooltip('');
        this.setHelpUrl('');
    }
};

I cannot define it successfully and I got a Uncaught TypeError: text.replace is not a function error. Anyone can help me ?

Dmitriy Fialkovskiy
  • 3,065
  • 8
  • 32
  • 47
ZhangJoker
  • 11
  • 2
  • I just copied your code into the playground and imported this XML: ` ` It worked fine except that the image (canada.svg) was not defined, so it fell back on the alt text. I replaced it with an image that I know exists: `../media/test_a.png` and it rendered fine. – fennel May 17 '18 at 21:06
  • Hrm... I checked this out in the Blockly playground here (https://blockly-demo.appspot.com/static/tests/playground.html) and it loaded, yet when I tried it in our own (outdated) Blockly environment, I replicated your issue. I assume the documentation references the most recent version, and I know our environment is a fork of a fairly old version. Are you by chance using a fork of an older Blockly version? – Amber B. Jun 28 '18 at 15:21

0 Answers0