Editor.getSelected() giving me undefined.
You can check if component.getTrait('href') gets anything first:
Read full answer below ↓Question
Hi @artf I want to append dynamic pages to the specific link trait.
Here is what i am using.
const component = editor.getSelected(); component.getTrait('link').set('options', [ { value: 'opt1', name: 'New option 1'}, { value: 'opt2', name: 'New option 2'}, ]);
This is giving component is undefined in the console because by default not any element is selected
Could you please guide me on this . I want to append that pages in list of link trait whenever i click on the link
Answers (3)
You can check if component.getTrait('href') gets anything first:
editor.on('component:selected', component => {
component.getTrait('href') && component.getTrait('href').set('options', data.list);
});
Thank you so much @Ju99ernaut Now,It working perfectly. Really appreciate your help. Closing this issue.
You can add that to each component type using:
const components = editor.Components.getTypes();
components.forEach(component => {
//manipulate traits here...
});
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3404
Style Manager Issue.
Hi @artf I want to hide and show style properties for specific component. After referencing this issue https://github.com/artf/grapesjs/iss...
Issue #3237
Add Trait For wrapper
Hi @artf I've added trait for wrapper this way. How can I perform the init function for the same Here is the code @artf Could you please he...
Issue #6249
Intialized custom color picker
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? ChromeReproducible demo link ---Describe the...
Issue #3228
Component Value is not changing
Hi @artf I've added a new component here is the code on selecting the h1 and h2 tag it's changing the value in the HTML section as you can...
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 →Related tutorials
In-depth guides on the same topic.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.