melvin
melvin

Reputation: 2621

cannot add item from connected list to sortable list

I have connected sortable list A and B. One item is fixed in list A called forbidden so that it cannot be sorted. When list A is empty (only with forbidden left) and trying to add item from list B, the item always get inserted after the fixed item (forbidden) in list A. I want it before fixed item (forbidden) in list A. I want it using jquery-ui-sortable without using any plugins.

Here is my fiddle

#UPDATE

Check this image. Isabelle from list B can be placed under forbidden when list A is empty (i.e, when list A contain only forbidden enter image description here

Upvotes: 1

Views: 72

Answers (1)

Ali Soltani
Ali Soltani

Reputation: 9927

You can do it by cancel option and cancle method like this:

$(function() {
  $(".list-A, .list-B").sortable({
    update: function(event, ui) {
      if ($(this).find('.forbidden').length > 0) {    
        if ($('.forbidden').index() < $(this).children().length - 1)
          $('.sortable').sortable("cancel");
      }
    },
    connectWith: ".sortable",
    cancel: '.forbidden'
  }).disableSelection();
});

Online demo (fiddleJs)

Upvotes: 1

Related Questions