Editor.getSelected() giving me undefined.
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 #2988
Trying to override of link trait
Hi @artf I am trying to add new types of trait Below is my code.It's updating the values in code also but on reload link trait will set to...
Issue #2951
typography sector not found
When using trying to add a font to the style manager, I use the following code: const prop = editor.StyleManager.getProperty('typography',...
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.