How to observe children changes in component
Is there an easy way to subscribe/listen to changes in the components/children of my custom component type? @scottccoates you can subscribe this way: cheers!
Read full answer below ↓Question
Is there an easy way to subscribe/listen to changes in the components/children of my custom component type? Perhaps an event I can subscribe to? Something like change:content?
I want to add traits to children of my container component. If the children leave the container, the traits should disappear.
I can think of 1 workaround. Something like:
// in the view
this.el.bind("DOMSubtreeModified",function(){
alert('changed');
});
Answers (3)
Is there an easy way to subscribe/listen to changes in the components/children of my custom component type?
@scottccoates you can subscribe this way:
init(){ // inside your model
this.listenTo(this.components().at(0),'change:prop-name', handler)
}
cheers!
@pouyamiralayi thanks. I need to watch for children leaving/entering my component. I'm not sure what you supplied will help or am I missing something?
@scottccoates this might help:
editor.on('component:add', model => console.log(model.parent().get('custom-name')))
editor.on('component:remove', model => console.log(model.parent().get('custom-name')))
cheers!
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2193
[QUESTION] Reset trait on edit the content of a custom component
Hi, I have a custom component which content can be changed by switching trait select options, but also can be edited similar to the text co...
Issue #3328
How can I update the nodeValue (text value) of components by inputs forms
Hello. Grapesjs is a great tool. Thanks for it. I want to update the text value of a component by inputs, how can I do that?? if a user fil...
Issue #3231
how to change gjs-ckeditor-format component
hi guys, we all know that gjs-ckeditor-plugin working with [data-gjs-type]="text" components. I wanna know , could we change this option? I...
Issue #3213
How to save the dynamically added traits
Hi, @artf, I have a custom component that has a button trait. When the button is pressed, I am adding a custom trait dynamically using comp...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Related tutorials
In-depth guides on the same topic.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.