Issue #603💬 AnsweredOpened December 4, 2017by krunal0391 reactions

Conditional traits

快速解答by ryandeba1

Hi @krunal039, The video component seems to do this already to some extent - see here. If you want to customize the traits further, you could probably do something like this (untested code, but copied and modified from something similar that I've done):

Read full answer below ↓

Question

is there way to have conditional traits? if is current component is youtube video then have some traits and if video is non-youtube then shows other traits?

Answers (2)

ryandebaDecember 4, 2017

Hi @krunal039,

The video component seems to do this already to some extent - see here. If you want to customize the traits further, you could probably do something like this (untested code, but copied and modified from something similar that I've done):

var videoType = editor.DomComponents.getType('video');

editor.DomComponents.addType('video', {
	model: videoType.model.extend({
		getYoutubeTraits() {
			return []; // replace this empty array with your desired traits
		}
	}),
	view: videoType.view
});
lock[bot]September 18, 2019

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...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.