Skip to content

FieldDropDown: Uncaught TypeError: Cannot read property 'firstChild' of undefined #1609

Description

@AnmAtAnm

Problem statement

Report of error during field init when dropdown is dynamically added by a mutator.

https://groups.google.com/forum/#!topic/blockly/FXZhA2Df06Y

See stack trace below.

Expected Behavior

A block mutator should be able to add a dropdown field to a block, followed by other fields or inputs, without crashing.

Actual Behavior

The below block definitions with mutator fails Uncaught TypeError: Cannot read property 'firstChild' of undefined in goog.dom.removeChildren(..).

See stack trace below.

Steps to Reproduce

  1. Create a test page with the below blocks.
  2. Add a select block to the workspace.
  3. Mutate the select block, appending the JOIN to the CONTAINER.
Blockly.Blocks['select'] = {
    init: function () {
        this.join_ = 0;
        this.updateShape_();
        this.setMutator(new Blockly.Mutator(['join']));
    }
    ,
    mutationToDom: function () {
        var container = document.createElement('mutation');
        container.setAttribute('join', this.join_);
        return container;
    }
    , 
    domToMutation: function (xmlElement) {
        this.join_ = parseInt(xmlElement.getAttribute('join'), 10);
        this.updateShape_();
    }
    , 
    decompose: function (workspace) {
        var topBlock = workspace.newBlock('container');
        topBlock.initSvg();
        var connection = topBlock.getInput('JOIN').connection;
        if (this.join_ == 1) {
            var itemBlock = workspace.newBlock('join');
            itemBlock.initSvg();
            connection.connect(itemBlock.outputConnection);
        }

        return topBlock;
    }
    ,
    compose: function (topBlock) {
        var itemBlock = topBlock.getInputTargetBlock('JOIN');
        if (itemBlock == "JOIN") {
            this.join_ = 1;
        } else {
            this.join_ = 0;
        }

        this.updateShape_();
    }
    , 
    updateShape_: function () {
        if (this.join_ == 1 && !this.getInput('JOIN')) {
            var input = this.appendValueInput("JOIN").setCheck("table").appendField(new Blockly.FieldDropdown([["INNER JOIN", "INNER JOIN"], ["LEFT JOIN", "LEFT JOIN"], ["RIGHT JOIN", "RIGHT JOIN"], ["FULL OUTER JOIN", "FULL OUTER JOIN"]]), "JOINS");
        } else if (this.join_ == 0 && this.getInput('JOIN')) {
            this.removeInput('JOIN');
        }

   
    }
};

Blockly.Blocks['container'] = {
    init: function () {
        this.setColour(60);
        this.appendValueInput("JOIN")
            .setCheck("join")
            .appendField("CONTAINER");
        this.setTooltip("");
        this.contextMenu = !1
    }
};

Blockly.Blocks['join'] = {
    init: function () {
        this.setColour(60);
        this.appendDummyInput()
            .appendField("JOIN");
        this.setOutput(true, "join");
        this.setTooltip("");
        this.contextMenu = !1
    }
};

Stack Traces

blockly_compressed.js:404 Uncaught TypeError: Cannot read property 'firstChild' of undefined
    at Object.goog.dom.removeChildren (blockly_compressed.js:404)
    at Blockly.FieldLabel.Blockly.Field.render_ (blockly_compressed.js:1972)
    at Blockly.FieldLabel.Blockly.Field.getSize (blockly_compressed.js:1974)
    at Blockly.BlockSvg.renderCompute_ (blockly_compressed.js:2101)
    at Blockly.BlockSvg.render (blockly_compressed.js:2097)
    at Blockly.FieldDropdown.Blockly.Field.forceRerender (blockly_compressed.js:1976)
    at Blockly.FieldDropdown.init (blockly_compressed.js:2193)
    at Blockly.Input.init (blockly_compressed.js:1983)
    at Blockly.BlockSvg.initSvg (blockly_compressed.js:2045)
    at Blockly.Mutator.workspaceChanged_ (blockly_compressed.js:1952)

Activity

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions