首页 > 解决方案 > Does Dragula accepts buffer the answer?

问题描述

I'm using dragula and wanted to have a heading within each container. I've managed to make the heading non-draggable via the moves attribute, but, then I also wanted to prohibit that elements can be dropped above the heading so I added:

accepts: function (el, target) {
            var itemPos = Array.from(el.parentNode.children).indexOf(el);
            var acceptDrop = itemPos > 0;
            console.log("Accept Drop = " + acceptDrop);
            return acceptDrop;
          },

In the console log, I can see that the acceptDrop is false when I move an element to the first position but the drop is possible anyway! But then I can't move it from that position. I.e. If the accepts returns false when the drag is initiated I can't drop the item anywhere, but if it starts with true I can drop it everywhere. Am I missing something or how can I make this dynamic and prevent drops at position zero?

(I know that I can put the heading outside the container with draggable items but that needs extra HTML nesting that shouldn't be needed)

标签: javascriptdragula

解决方案


推荐阅读