Ignore, bad use of Trait
No community answers yet. Open the original discussion on GitHub to share your solution.
Question
Hello,
Version: 0.16.18 Are you able to reproduce the bug from the demo? [X] Yes [ ] No
What is the expected behavior? Only add one trait, being able to test empty trait addition
Describe the bug detailed Adding trait with:
const component = editor.getSelected();
if (!component.getAttributes()['newtrait']) {
component.addTrait('newtrait');
}
Adds a new empty trait ... each time this component is selected:

Because getAttributes is undefined:
editor.getSelected().getAttributes()['newtrait']
undefined
Until I fill newtrait with a value and newtrait value exists.
It still keeps all the duplicate fields:

Maybe I missed something? Or is it a bug? Thank you EDIT: fixed by setting a value to the trait afterward :) Obvious, sorry!
Answers (0)
No answers yet.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3731
Text element not able to be selected twice after extended with events
Version: 0.17.25 Are you able to reproduce the bug from the demo?[ ] Yes[x] No What is the expected behavior? Update a existing component o...
Issue #3457
Custom trait input not working
Hi @artf ! Version: 0.17.3 Are you able to reproduce the bug from the demo?[ ] Yes[x] No What is the expected behavior? The input is create...
Issue #3209
When in preview mode, the toolbar is only being hidden but still clickable
Version: 0.16.22 Are you able to reproduce the bug from the demo? Yes What is the expected behavior? When the use presses the preview butto...
Issue #3310
Tablet and mobile view not resizing
Version: The one in the demo Are you able to reproduce the bug from the demo? [X] Yes [ ] No What is the expected behavior? Mobile and tabl...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.