[BUG] Checkbox trait does not load as checked even when the trait value is true
Question
Hi,
I'm using Grapesjs version 0.14.33.
I'm loading some components when the form loads and I have a component with a checkbox trait. When I load the component using editor.DomComponents.load, I'm loading the checkbox with the value true, which means that the trait should be rendered with the checkbox already checked. This is not working. However, when I check the trait value from the DOM object using the editor.getComponents().models[0].get('traits').models[0].get('value'), it returns true.
Browser Used for Testing : Chrome v 69.0.3497.100
Actual Behaviour : The checkbox trait does not render as checked but the trait value in the DOM object is true.
Expected Behaviour : The checkbox trait should render as checked if the component is loaded with the trait value of true.
JS Fiddle link to reproduce the issue : https://jsfiddle.net/g3zh12r7/4/
Thanks
Answers (3)
- Update your grapesjs version
- The trait reads the value from the component, so place the initial value at the component level, not at the trait one
Hi Artf,
Thanks for your reply. Can you please provide me a sample link, or if you could please update the jsfiddle, to explain what you mean by "place the initial value at the component level".
Thanks
I mean, when you add the checkbox element, put checked there
<input data-gjs-editable="false" .... type="checkbox" ... checked/>
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1535
[Bug]: After custom component is deleted the Trait's view does not clear out
Hi, I'm using the grapesjs library version 0.14.33. I've created some custom components and I've noticed that on deleting the components th...
Issue #943
[BUG]: Checkbox trait doesn't remove attribute when unchecked
When html attributes are true or false, the should either exist or not exist. For example, required. This don't have a value in HTML5. Vali...
Issue #1424
Checkbox trait value is rendered differently in view (render()) vs model (getHtml())
I have a custom component with a checkbox trait 'show-name'. When the trait value is 'true', the component renders in the view to the attri...
Issue #1047
[BUG] Model not able to change after changing value in custom Select dropdown menu.
Hey, I'm using CDN link for grapes js from unpkg.com In my project, I've used custom trait as a drop-down select menu which changes HTML us...
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.