Issue #1030Opened April 12, 2018by francesca-cicileo0 reactions

[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)

arthuralmeidapApril 12, 20180 reactions

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

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

artfApril 14, 20180 reactions

@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' }))

lock[bot]September 17, 20190 reactions

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.

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.