grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

Restrict draggable elements to parent?

Open austinbiggs opened this issue 8 years ago • 6 comments

I'm not sure if this already exists and I haven't seen it yet (apologies if that's the case). Is there a way to restrict where certain draggable elements are droppable?

Say I have a list:

<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>

And I want the user to be able to rearrange the list items, but restrict them from dragging outside of the <ul>.

similar to http://api.jqueryui.com/draggable/#option-containment

austinbiggs avatar Jan 03 '18 23:01 austinbiggs

Sure, you can make use of data-gjs-* attributes (eg. data-gjs-draggable="ul") Check the last example code here https://github.com/artf/grapesjs/wiki/Blocks

artf avatar Jan 04 '18 00:01 artf

It seems you've thought of everything, you've done such an amazing job w/ GrapesJS! 😄

austinbiggs avatar Jan 04 '18 00:01 austinbiggs

Thanks Austin :)

artf avatar Jan 04 '18 00:01 artf

Sure, you can make use of data-gjs-* attributes (eg. data-gjs-draggable="ul") Check the last example code here https://github.com/artf/grapesjs/wiki/Blocks

Is it possible to specify a div class name or id in case i have a lot of nested divs?

sakshigarg9 avatar Feb 25 '19 09:02 sakshigarg9

@sakshigarg9 you can use any query selector (eg. div#some-id > .class)

artf avatar Feb 28 '19 12:02 artf

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.

lock[bot] avatar Feb 28 '20 14:02 lock[bot]