Dropdowns are dragged into other containers, but not themselves?

Following the link to the jQuery UI Droppable example: Cart. I rewrite it for a test. But there are some problems.

Let's pretend that:

product container: drag the product into the container of the shopping basket.

<div class="products">
  <ul>
    <li> product 1 </li>
    ...
  </ul>
</div>

and a basket basket for shopping:

<div class="shoppingCart1">
... dropped products here
</div>

and other containers for purchases :

<div class="shoppingCar2">
... dropped products here
</div>

And I want shoppingCart1 products to be dragged into another container of the shopping basket , but not by myself, and vice versa. E..g:

problem:

s * hoppingCart1 *, shoppingCart1 . , , . , shoppingCart1 shoppingCart1, shoppingCart1.

!

JQuery UI Droppable: ! [ , ]

    this.igtoMDMovieList = $('<div />',{'class':'igtoMDMovieList'})
                            .appendTo(this.igtoMDMovieListWrapper);


        this.igtoMDMovieListOL = $('<ol />',{'class':'igtoMDMovieListOL'})
                                    .html('<li class="placeholder">Add your items here</li>')
                                    .appendTo(this.igtoMDMovieList)
                                    .droppable({
                                        accept:'li', 
                                        drop: function( event, ui ) {

                                            $( "<li></li>" )
                                                .text( ui.draggable.text() )
                                                .appendTo(obj.igtoMDMovieListOL)//$(this).children()
                                                .draggable({
                                                    appendTo: "#desktopFrame",
                                                    helper: "clone"
                                                })

                                        }
                                    })
                                    .sortable({
                                        items: "li:not(.placeholder)",
                                        sort: function() {
                                            // gets added unintentionally by droppable interacting with sortable
                                            // using connectWithSortable fixes this, but doesn't allow you to customize active/hoverClass options
                                            $( this ).removeClass( "ui-state-default" );
                                        }
                                    });
+3
1

, . data-id, .

$("#products li").draggable({
    appendTo: "body",
    helper: "clone"
});
$(".shoppingCart ol").droppable({
    activeClass: "ui-state-default",
    hoverClass: "ui-state-hover",
    drop: function(event, ui) {
        var self = $(this);
        self.find(".placeholder").remove();
        var productid = ui.draggable.attr("data-id");
        if (self.find("[data-id=" + productid + "]").length) return;
        $("<li></li>", {
            "text": ui.draggable.text(),
            "data-id": productid
        }).appendTo(this);
        // To remove item from other shopping chart do this
        var cartid = self.closest('.shoppingCart').attr('id');
        $(".shoppingCart:not(#"+cartid+") [data-id="+productid+"]").remove();
    }
}).sortable({
    items: "li:not(.placeholder)",
    sort: function() {
        $(this).removeClass("ui-state-default");
    }
});

: http://jsfiddle.net/petersendidit/S4QgX/

+2

Source: https://habr.com/ru/post/1787083/


All Articles