Issue #2991✓ SolvedOpened September 2, 2020by Abhisheknanda13444633 reactions

Editor.getSelected() giving me undefined.

Quick answerby Ju99ernaut2

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)

👍 Most helpfulJu99ernautSeptember 5, 2020

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);
});
Abhisheknanda1344463September 6, 2020

Thank you so much @Ju99ernaut Now,It working perfectly. Really appreciate your help. Closing this issue.

Ju99ernautSeptember 5, 2020

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.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

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.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.