After update the component attributes using editor.on('component:add',function(){}); The blue box item is not correct.
Question
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.

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)
@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
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.
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.
Issue #987
[BUG/Question] Dropdown indicator not displayed for a custom trait
Hello, the dropdown (select) element arrow indicator icon is not rendered when adding a custom trait to a component: I'm using following co...
Issue #1990
[QUESTIONS] need to call method before remove the html component
Hi, I need to call the method before remove the HTML component. how can I do that calling method like editor.on('block:drag:stop', function...
Issue #417
Add Setting button to custom component.
Hello, How can I create a setting or you can say edit button for my custom component? LIke 4th option on this image:
Issue #692
After pull the new commit, the grapesjs not working on IE and show following error.
Hi @artf , After pull the new commit, i get the error on IE, can you please take a look for this? Thanks.
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.