Search code examples
jquery-uidraggablejquery-ui-droppable

jQuery UI draggable revert


I have 4 tables generated dynamically. There is two divs in each cell (td). All the divs are droppable. I dont know why but only the 2nd div accepts the draggable, the first one reverts it. There is no different between the two divs (exepts one has a "dotted" class).

Here is the jsbin: http://jsbin.com/OMIbOGU/22/edit

JS

$("document").ready(function(){

  function init(){
    var table = $("<table></table>");
    $("body").append(table);
    for(var i=0 ;i < 9; i++){
      var row = $("<tr></tr>");
      var cell =  $("<td></td>");
      for(var j = 0;j<2;j++){
        var slot = $("<div></div>").addClass('slot');

        slot.droppable({
          accept: ".unassigned"
        });

        if (j!==1)
          slot.addClass("dotted");
        cell.append(slot);
      }
      row.append(cell);    
      table.append(row);

    }

    $(".unassigned").draggable({
      revert: "invalid",
      snap: "td div"
    });
  }
  for(var i = 0 ; i<4;i++)
  init();
});

Solution

  • if you add

    tolerance: 'touch'
    

    to the droppable it works. Which points to it being more of a css issue than one with the script.

    Updated JS BIN