Issue #1543Opened October 26, 2018by TommyLjung0 reactions

[Question] Enable Traist-checkbox by default

Question

Hi.

I am new to GrapesJs and really liking it so far. But now I have a (probably beginner) question:

How can I make a trait-checkbox be selected by default? I have tried with: traits: [ { type: 'checkbox', label: 'Loop', name: 'model-loop-bool', changeProp: 1, selected: 'true', }],

But "selected" or "checked" is not the right attribute to set, can someone please help me with this basic thing?

Thanks!

Answers (2)

artfNovember 2, 20180 reactions

If you use changeProp you get the value from the component value, eg:

...
defaults: {
	...
	'model-loop-bool': true, // <- default value
	traits: [{ 
		type: 'checkbox', 
		label: 'Loop', 
		name: 'model-loop-bool', 
		changeProp: 1, 
	}]
}

without changeProp, it would be:

defaults: {
	...
	attributes: {
		'model-loop-bool': true,
	},
	traits: [{ 
		type: 'checkbox',
		label: 'Loop', 
		name: 'model-loop-bool', 
	}]
}
lock[bot]November 2, 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.