jquery droppable -> avoid multiple drops of the same object

前端 未结 2 1446
不知归路
不知归路 2021-01-14 19:23

I have a container with different draggable -elements and there is a list of some \"target\" divs, where the user can drop the draggable elements.

Example: Imagine,

2条回答
  •  余生分开走
    2021-01-14 19:49

    okey so i wanted to improve that code a little bit and drop an error msg why the item is not accepted. but it adds the item prints error then it doesnt accept then no prints why does happen? There are 2 limitations;

    • Check to see if the item is added twice if not;
    • then check to see if count of all the item more than 4 or equal?

      accept: function(draggable) { if($(this).find("#copy-" + draggable.attr("menu-item-id")).length == 0) {

          if($(this).find('li.dinamik').length>=4)
              {
                  $("#errorMsg").show("slow", function(){ $(this).hide(6000);}).text("Can not have more than 4 items");
                  return false;    
              } return true;
      } else if($(this).find("#copy-" + draggable.attr("menu-item-id")).length >= 1)
          {
              $("#errorMsg").show("slow").text("Cant Duplicate"+draggable.text());
              return false;
          }
      

      }

提交回复
热议问题