Nestable
Nestable copied to clipboard
Support for drop rejects with multiple rule-action sets
Hey guys. How is this supposed to work actually? Is there an example how to use the reject option? Thanks!
Hi @schneikai, the use of the reject option is quite simple but, indeed, not documented, here's an example :
$('#nestable').nestable({
reject: [{
rule: function() { // The this object refers to dragRootEl i.e. the dragged element. The drag action is cancelled if this function returns true
return $(this).find('>ol>input input').length > 0; // The rule here is that it is forbidden to have nested inputs in the hierarchy
},
action: function(nestable) { // This optional function defines what to do when such a rule applies. The this object still refers to the dragged element, and nestable is, well, the nestable root element
alert('You can\'t do that !');
}
},
{ /* You can add another rule (and possibly an associated action) here */}
]
});
Nice! Thank you!
Hi @bperel , i know this is an old branch but fit's my current project quite well. Do you know if it's also possible to reject something based on the destination it's moved to? For example i want to prevent people dropping items in the root of my tree but all other 'levels' are OK. 1-2 --2-3 --2-3 --2-3-4 In the above example lvl1 would be root, so offlimit's. But all others are fine so something from lvl4 could be dropped in lvl2 etc. etc. having a hard time with this, hope you could share some insights :). Thanks in advance!
@sebVier I'll check this in the next days
Awesome thanks a lot!
@sebVier I had a look at this. You may have been confused by the inaccurate comments that I put on my code. I fixed that and updated from upstream into https://github.com/bperel/Nestable. Demo is on http://bperel.github.com/Nestable/
@bperel Thank you so much! work's great now!
@bperel so good. I have implemented a method like reject drop, after that I see your fork. :smile: :smile: :smile:
@bperel Thanks you for this solution. :+1: