question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can I restrict what blocks that can be dropped into a container

See original GitHub issue

My intent is to create a block that should allow only image components (I’m using the default one from grapes-blocks-basic) to be dropped inside it.

I have the following test code:

  comps.addType('image-container', 
  {
    model: defaultModel.extend(
    {
      // Extend default properties
      defaults: Object.assign({}, defaultModel.prototype.defaults, 
      {
        droppable: "img",
      }),
    },
    {
      isComponent: function(el) 
      {
        if(el.tagName == 'DIV' && $(el).hasClass("image-container"))
        {
          return {type: "image-container"};
        }
      },
    }),
    view: defaultView
  });

  blockManager.add('image-container', 
  {
    label: 'Image Container',
    attributes: {class:'fa fa-pencil'},
    content: '<DIV class="image-container"></DIV>',
    category: 'Test Blocks',
  });  

However, when I run the above code, what happens is that I can’t drop an image component inside the Image Container. The green drop cursor only appears around the top/bottom/sides of the container but it won’t appear inside it. Actually, I can’t drop ANY component inside it.

I kind of assumed that the “droppable” property could work the same way as the “draggable” property does in the example here: https://github.com/artf/grapesjs/wiki/Components. The source for Component.js says:

    // Indicates if it's possible to drag the component inside others
    // Tip: Indicate an array of selectors where it could be dropped inside
    draggable: true,

    // Indicates if it's possible to drop other components inside
    // Tip: Indicate an array of selectors which could be dropped inside
    droppable: true,

So it looks like they should work the same way. Am I doing something wrong?

Is it better to do this the other way around? i.e. Create a custom image component, and restrict it’s draggable property? (I haven’t tried this yet - I’m not sure if I can override/extend the default image type’s behavior)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
roytangcommented, Nov 11, 2017

This fix works. Thanks!

0reactions
lock[bot]commented, Sep 18, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved - Preventing drops from containers | SpigotMC
I already have the WorldGuard global region set to item-drop: deny, but that only prevents players from dropping items. How can I prevent ......
Read more >
Dropper - Minecraft Wiki - Fandom
A dropper is a block that can be used to eject items or to push items into another container. A dropper can be...
Read more >
Secure Your Containers with this One Weird Trick - Red Hat
Using the docker run --cap-drop option, you can lock down root in a container so that it has limited access within the container....
Read more >
Unable to Drag/Move Blocks within Atomic Block Container ...
I create a brand new container, and I can drag blocks into it, but once they are in, they are stuck. I can't...
Read more >
Custom blocks - Help Center - WordFly
Blocks are essentially small pieces of code that can be dropped into your designs. When a block is dropped into an email or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found