Issue #1247Opened June 29, 2018by algodata440 reactions

Text disappear after creating a new type

Question

Hello!

I am creating a new block that will open a modal during the creation (drag and drop https://github.com/artf/grapesjs/issues/174 really helped me and it works.

But it had a surprising side-effect: When I select and deselect a text component, the text disappear. Here is the code, I think I changed the defaultType property unintentionally:

var defaultType = editor.DomComponents.getType('default');
   	editor.DomComponents.addType('importType', {
   	 		model: defaultType.model.extend({
   	 				isComponent: function(el){
   	 					if(el.tagName == 'IMPORTTYPE'){
   	 						return {type: 'importType'};
   	 					}
   	 				},
   	 		}),
   	view: defaultType.view.extend({
   	     init() {
   	       this.listenTo(this.model, 'active', this.doStuff); // listen for active event
   	     },
   	     doStuff() {...}
   	  }),
   	});

Answers (3)

artfJune 30, 20180 reactions

Wrong position for isComponent, it should be passed in the second argument object

defaultType.model.extend({
	isComponent //<- wrong
}, {
	isComponent //<- correct
})

So it's like not declaring it, and as mentioned in Components

As you're putting a new Component type on top of the stack, not declaring isComponent() might probably break stuff, especially if you extend the default one.

algodata44July 2, 20180 reactions

It works perfectly, thank you!

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.