Issue #687Opened December 27, 2017by TWCM1 reactions

After update the component attributes using editor.on('component:add',function(){}); The blue box item is not correct.

Question

Code SnippetTEXT
After update the component attributes using   editor.on('component:add',function(){}); 
The blue box item(it mean the action icon) is not correct. The copy icon should not show.

![image](https://user-images.githubusercontent.com/2859394/34370766-dad79d20-eb01-11e7-82f1-0d0b5346273c.png)

Javascript
`    var hasClass  = function(model, className){
        return model.get('classes').where({name: className}).length;
    }
    var updateProperty = function (model) {
        
        model.set({
            draggable: false,
            droppable: false,
            copyable: false,
            removable: false,
            selectable: false,
            editable: false
        });

        if (hasClass(model,"editable")) {
            model.set('editable', true);
        }
        
        if (hasClass(model,"selectable")) {
            model.set('selectable', true);
        }
        if (hasClass(model,"content-block")) {
            model.set('draggable', '#wrapper');
            model.set('droppable', false);
            model.set('selectable', true);
          
        }
        
        
        console.log(model);
        model.get('components').each(child => updateProperty(child))
  

    }
    editor.on('component:add', function (model) {

        updateProperty(model);
        //console.log($(model).hasClass("editable"));

    })`

Answers (3)

artfDecember 28, 20171 reactions

@tommywulove ok I close this then

@ryandeba As you already mentioned the toolbar is created when the component is initialized so, honestly, I don't see it as a bug and overall, your snippet should work well. BTW thanks for your willingness to help

ryandebaDecember 28, 20170 reactions

Hi @tommywulove,

I believe the "blue box item" that you're referring to is the component toolbar. All of the toolbar buttons are created for each component as that component is initialized; changing a property (like copyable) does not automatically update the toolbar.

You could probably force the toolbar to update by clearing out the toolbar property on the component and manually call initToolbar()...maybe something like this:

model.set("toolbar", "").initToolbar();

@artf - would you consider this a bug or is this the desired behavior? If you think it should be changed, I'd be happy to work on a pull request for it.

TWCMDecember 28, 20170 reactions

Hi @ryandeba , Thanks for your reply. I found that the component:add event is not suitable for my case, so i used component type to solve my problem. I updated the component type and added some new component type to control which action can be use in the element.

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.