Issue #2396💬 AnsweredOpened November 11, 2019by naveen-156973 reactions

Can't select the model using editor.select()

快速解答by naveen-156971

@artf , @pouyamiralayi :I need this condition inside the 'canvas:drop' event editor.on('canvas:drop', ()=>{ ... ... // My code to select the first component is here //... ... })

Read full answer below ↓

Question

I am trying to select the first component in the editor by using editor.select(editor.DomComponents.getComponents().models[0]). It is not working.

Answers (3)

naveen-15697November 11, 2019

@artf , @pouyamiralayi :I need this condition inside the 'canvas:drop' event editor.on('canvas:drop', ()=>{ ... ... // My code to select the first component is here //... ... })

pouyamiralayiNovember 11, 2019

@naveen-15697 you can achieve this with:

editor.on('block:drag:stop', (m) => {
    if(m){
       editor.select(editor.getComponents().models[0])
    }
})

cheers!

naveen-15697November 11, 2019

@pouyamiralayi Thanks! It's working now.

@artf , But, Why it is not working in 'canvas:drop' event?

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.