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

Error while using workspace.removeBlockById() #3940

Closed
NavpreetDevpuri opened this issue Jun 7, 2020 · 4 comments
Closed

Error while using workspace.removeBlockById() #3940

NavpreetDevpuri opened this issue Jun 7, 2020 · 4 comments
Labels
issue: bug Describes why the code or behaviour is wrong

Comments

@NavpreetDevpuri
Copy link

NavpreetDevpuri commented Jun 7, 2020

i have a custom block with type a

Blockly.Blocks['a'] = {
        init: function() {
            this.appendValueInput("a1")
                .setCheck(null)
                .appendField(new Blockly.FieldDropdown([["aaa","0"], ["b","1"], ["c","2"]]), "a2");
            this.setColour(130);
            this.setTooltip("");
            this.setHelpUrl("");
        }
    };
    Blockly.JavaScript['a'] = function(block) {
        var dropdown_a2 = block.getFieldValue('a2');
        var value_a1 = Blockly.JavaScript.valueToCode(block, 'a1', Blockly.JavaScript.ORDER_ATOMIC);
        // TODO: Assemble JavaScript into code variable.
        var code = '...;\n';
        return code;
    };

i run workspace.removeBlockById(workspace.getBlocksByType("a")[0].id) in console and it show following error as shown in following gif
1tks3hbAD8

It should delete block

@NavpreetDevpuri NavpreetDevpuri added issue: triage Issues awaiting triage by a Blockly team member issue: bug Describes why the code or behaviour is wrong labels Jun 7, 2020
@BeksOmega
Copy link
Collaborator

Hi! When filing an issue please fill out all of the pre-made sections. That helps people figure out what could be going on =)

Lucky for you someone else had the same problem a few weeks ago =) You want to use block.dispose() (docs) not .removeBlockById. As you can see that function is package.

I hope that helps! If you have any further problems (specifically related to disposing) I think it might be best to redirect your questions to the forums. Thank you :D

@NavpreetDevpuri
Copy link
Author

NavpreetDevpuri commented Jun 7, 2020

thanks for replying
I want to achive something like "delete a block but don't want this deleted block goes into recyclebin"
thats why i used .removeBlockById

mainly my main motive was to achive something like "update dropdown list of a block programmically"
i was able to do that by simply reinitialize block by Blockly.Blocks['a'] but this creates a problem that the blocks that are inside workspace those blocks just don't update in any way but those blocks that are inside toolbox are updated then i tried to delete those unchanged blocks and try to add new ones it works but then these deleted blocks just appears inside recyclebin.

now i just

  1. export xml of blocks
  2. clear the workspace
  3. reimport blocks from xml
    it works fine it update blocks.

Thats what i want to achive
HSgjRh9DEn

i think blockly should provide this method in documentation that How can we modify blocks programmically at any time ? because i was searching for a method to do that and i don't found any usefull information and this is a important question.

OR may be include some function to class workspace something like workspace.refresh() that refresh both toolbox and workspace area something similar to workspace.refreshToolboxSelection() that refresh only toolbox
YroRl89Pja

@NavpreetDevpuri
Copy link
Author

NavpreetDevpuri commented Jun 8, 2020

@BeksOmega i want to know that what is the name of workspace area where we put blocks ? can we say it "workspace area" i think "workspace area" is including both toolbox and area. likewise there is a name for right menu "toolbox".

@samelhusseini
Copy link
Contributor

The trashcan uses Blockly events to determine when to add blocks to its list of blocks.
You can disable events and then call block.dispose(), ie:

Blockly.Events.disable();
block.dispose();
Blockly.Events.enable();

Blockly does support dynamic dropdowns, see:
https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/dropdown#dynamic_dropdowns

If you're unsure whether what you've stumbled upon is a bug or if you need advice / have questions about what you're trying to achieve, the Blockly forum is a better place to ask questions.

@moniika moniika removed the issue: triage Issues awaiting triage by a Blockly team member label Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug Describes why the code or behaviour is wrong
Projects
None yet
Development

No branches or pull requests

4 participants