Nestable icon indicating copy to clipboard operation
Nestable copied to clipboard

Support for drop rejects with multiple rule-action sets

Open bperel opened this issue 11 years ago • 10 comments

bperel avatar Oct 04 '13 12:10 bperel

Hey guys. How is this supposed to work actually? Is there an example how to use the reject option? Thanks!

schneikai avatar Dec 17 '13 17:12 schneikai

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 */}
      ]
});

bperel avatar Dec 18 '13 17:12 bperel

Nice! Thank you!

schneikai avatar Dec 19 '13 10:12 schneikai

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 avatar Dec 13 '16 10:12 sebVier

@sebVier I'll check this in the next days

bperel avatar Dec 14 '16 09:12 bperel

Awesome thanks a lot!

sebVier avatar Dec 14 '16 12:12 sebVier

@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 avatar Dec 17 '16 14:12 bperel

@bperel Thank you so much! work's great now!

sebVier avatar Dec 18 '16 09:12 sebVier

@bperel so good. I have implemented a method like reject drop, after that I see your fork. :smile: :smile: :smile:

jerviscui avatar Dec 20 '16 11:12 jerviscui

@bperel Thanks you for this solution. :+1:

bilalyilmax avatar Jan 20 '18 11:01 bilalyilmax