2014-01-22 24 views
0

目標:我想要拖放。我想在單元格之間進行排序。但是,一旦單元格被填滿,我不希望能夠將另一個項目放入/分類到單元格中。它應該是禁止的。我已經能夠通過成功地禁用拖/放如下:jQuery,防止可排序和可拖動之後放入單元格

$(this).droppable("option", "disabled", true); 

我所擁有的一切,除了我仍然可以拖動/排序從另一小區的小區工作。我注意到當我這樣做時Stop事件被調用。如果我可以禁用'停止'就像我在上面的代碼行中禁用'drop'那樣會很好。

這裏是一個小提琴,顯示我的問題: Fiddle Me This

回答

0

這裏是我最後不得不做(見「接收」事件)。看起來可能有一個更清潔的方式,但是這個工作:

$(".droppedFields").sortable({ 
     cancel: null, // Cancel the default events on the controls 
     connectWith: ".droppedFields", 
     stop: function (event, ui) { 
      makeUnDroppable(); 
     }, 
     receive: function (event, ui) { 
      var source = ui.item; 
      var target = $(this); 

      var newCombinedTargetLength = target.text().length; 
      var sourceLength = source.text().length; 

      // cancel the sort if something is already there 
      if (newCombinedTargetLength - sourceLength > 0) { 
       $(ui.sender).sortable('cancel'); 
      }    
     } 
    }).disableSelection();