I'm trying to get dragItem_1
to only be accepted by target_1
and so on.
I'd like to dynamically change the accept
parameter to whatever the id
of the item being dragged is.
I can get it to work by defining each draggable and droppable item, but since the amount of items and targets are user generated I need to do it dynamically.
$( function() {
$( ".js-draggable-box" ).draggable({
revert: "invalid",
start: function( event, ui ) {
var item = ui.draggable;
var id = $(item).attr('id');
console.log(id)
}
});
$( ".js-drop-target" ).droppable({
accept: ".js-draggable-box",
drop: function( event, ui ) {
var dropped = ui.draggable;
var droppedOn = $(this);
$(this).addClass( "c-drop-target--correct" ).droppable("disable");
$(dropped).detach().css({top: 0,left: 0}).appendTo(droppedOn).draggable("disable");
}
});
} );
I've also tried to get the ID on the start
event but I get an undefined.