[Question] Firing events with custom components
Question
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.
Answers (3)
Just for tests purposes, try to listen all changes on your model.
try with this.listenTo(model, 'change') and see what you get.
@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' }))
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.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #701
Modifying a component in the editor clears the model content
What I'm trying to achieve: I have special "data-" attributes on some of the components I pull into the editor. When one of these is modifi...
Issue #1959
[Question] Edit innerHTML in a custom button
Hi All, I am trying to change the text in a button component, but I am not able to edit it. I added this type: I included the editable: tru...
Issue #460
When the component's view modifies the HTML, text components are no longer editable
I'm trying to build a custom component that contains some lorem ipsum text in the content, for editing once it's on the canvas. But I also...
Issue #1655
[Question] isComponent() is not invoked
I'm trying to make a plugin, but I have a problem with isComponent. My component does not call it whene the editor loading the code, this i...
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.