Traits type Checkbox not checked from the initialization of the Component type.
Question
Hi, Artur
When I try to check traits (type: checkbox) from the init() of the domCom Type the value set as true but not checked. Code:
traits: [
{
type: 'checkbox',
label: 'Display Pagination',
name: 'pagination',
changeProp: 1
}
]
....
init()
{
var pagination = this.get('traits').where({ name: 'pagination' })[0];
**var paginationData = "true"; //(can came from DB)**
pagination.set('value', paginationData == "true" ? true : false);
}

Thanks man for your great work
Answers (3)
The trait reads from the component, edit the component itself not the trait value.
this.set('pagination', paginationData == "true" ? true : false)
No, I just want to checked the trait not the componen y.
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.
Issue #1543
[Question] Enable Traist-checkbox by default
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 sel...
Issue #1460
Hide Trait Element
How can I hide a trait element while creating a trait for the component. Is there any way like display:none or hidden:1. How can I show or...
Issue #975
[Question] Default values for traits field
I have created component with certain traits. I am not able to assign default value to traits by passing values. It is coming as undefined...
Issue #718
Add Description to trait
Is there way to add description to trait? we have below trait and want to add description so user understand what is purpose of it. traits:...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.