grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

[Question] Firing events with custom components

Open francesca-cicileo opened this issue 8 years ago • 3 comments

I'm trying to build a plugin for Grapesjs with some custom components, and I'm having trouble with triggering events and interacting with the component in the code. One problem I am having is that I added an attribute to the model for a custom text component. In the script for that text component, I change the attribute if the user has typed a certain character in the component. In the view for the component, I have a listener for the attribute: this.listenTo(model, 'change:customAttribute', this.doSomething);. My issue is that doSomething is never called, even though I can see that the attribute is changing through print statements in the console. Any advice? I would also really like to know if there is any way to detect the change in the custom attribute from the index.html file script, after initializing the editor (in a setup similar to the Grapesjs newsletter and webpage plugins)? Thank you.

francesca-cicileo avatar Apr 11 '18 21:04 francesca-cicileo

Just for tests purposes, try to listen all changes on your model.

try with this.listenTo(model, 'change') and see what you get.

arthuralmeidap avatar Apr 12 '18 18:04 arthuralmeidap

@francesca-cicileo 'change:*' is used for model's properties (eg. tagName, removable, etc.), probably you're looking for change:attributes:ATTR-NAME. Be sure to update model's properties properly (eg. model.addAttributes({ attrName: 'value' }))

artf avatar Apr 14 '18 13:04 artf

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Sep 17 '19 18:09 lock[bot]