Issue #1904Opened March 19, 2019by sakshigarg91 reactions

Get change in property float

Question

I'm trying to listen to the change in the 'float' property whether it was shifted to the 'left' or 'right' or 'none' in Style Manager using an event but my code doesn't seem to give the desired result.

  editor.on('component:styleUpdate:float', (model) => 
  { console.log('style update', editor.StyleManager.getProperty('General','float')); });

It gives style update null as the output. Desirable output would be float:right, float:left or float:none

Answers (3)

prashant2018March 23, 20191 reactions

You can use the "model" passed as a parameter to get the current property. After inspecting the model object I figured out we can get the style using model.attributes.style

You should get the desired output by modifying your code snippet in the following way: editor.on('component:styleUpdate:float', (model) => { console.log('style update', model.attributes.style); });

prashant2018March 24, 20190 reactions

@sakshigarg9 The approach I mentioned above is not working for some of the components, to be more precise what I observed is that the style property is giving empty string on the components which have a class defined.
Your approach of using editor is correct and also works for all the components, only thing is you were using incorrect sector id "General" instead of "general". Also, you need to extract the value of float in the following way editor.StyleManager.getProperty('general','float').attributes.value

The below code snippet works for all the components in the grapesjs-preset-webpage as I tested them. I think it should also work on your implementation:

editor.on('component:styleUpdate:float', (model) => 
{ 
 console.log('style update', editor.StyleManager.getProperty('general','float').attributes.value); 
});
lock[bot]March 27, 20200 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.