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

Calling setTooltip on a field label or image during Block.init() crashes #2030

Closed
RoboErikG opened this issue Aug 29, 2018 · 3 comments
Closed
Assignees
Labels
component: fields issue: bug Describes why the code or behaviour is wrong

Comments

@RoboErikG
Copy link
Contributor

Problem statement

The field label and image implementation of setTooltip depends on the svg elements having been created. This doesn't happen until well after the block's init(), which causes a crash if you try to set the tooltip on a field during init().

Expected Behavior

Should be able to configure field tooltips during init()

Actual Behavior

Crashes

Steps to Reproduce

  1. Create a block with the following definition
    Blockly.Blocks['test_1'] = {
    init: function() {
    this.appendDummyInput('in1');
    var in1 = this.getInput('in1');
    var field = new Blockly.FieldLabel('Test');
    field.setTooltip('Test tooltip');
    in1.appendField(field);
    }
    };
  2. Create a new test_1 block.

Stack Traces

field_label.js:119 Uncaught TypeError: Cannot set property 'tooltip' of undefined
at Blockly.FieldLabel.setTooltip (field_label.js:119)
at Blockly.BlockSvg.init (:10:9)
at Blockly.BlockSvg.Blockly.Block (block.js:165)
at new Blockly.BlockSvg (block_svg.js:99)
at Blockly.WorkspaceSvg.newBlock (workspace_svg.js:579)
at :1:44

Replace with error stack trace.

Operating System and Browser

Additional Information

Proposed fix:
in setTooltip

  • Save the tooltip on the field directly.
  • If the UI exists, set it on the UI
  • Otherwise wait until field.init() is called to set the tooltip on the UI.
@RoboErikG RoboErikG added issue: bug Describes why the code or behaviour is wrong affects: master component: fields labels Aug 29, 2018
@rachel-fenichel rachel-fenichel added this to the Backlog milestone Aug 31, 2018
@rachel-fenichel
Copy link
Collaborator

Did these tooltip-related functions ever work? The FieldImage one does something very different from the function description; I can't tell if the FieldLabel one works as-is.

@NeilFraser
Copy link
Member

Go to the playground. Create a 'not' block. Then enter the following in the console:
workspace.topBlocks_[0].inputList[0].fieldRow[0].setTooltip('Hello')
Seems to work.

@alschmiedt
Copy link
Contributor

Verified Fix. Looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: fields issue: bug Describes why the code or behaviour is wrong
Projects
None yet
Development

No branches or pull requests

5 participants