[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)
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',
}]
}
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 #1869
[QUESTION] how to add extra field in input traits
Hi, I want to add the new field in default input traits. for example:- i need to add {label: binding, name:binding} in already exist input...
Issue #1779
Traits type Checkbox not checked from the initialization of the Component type.
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: Thank...
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:...
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...
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.