I have 2 columns every column has 3 cards and every card has a checkbox.
my code run as drag and drop every card alone but
i want to drag and drop multiple selected/checked cards in one movement and uncheck checkboxes when cards drop.
see live example or snippet to live preview.
$("#card-list").droppable({
accept: $(".card").draggable({
revert: true,
opacity: .5
}),
drop: function( event, ui ){
var dropped = ui.draggable;
$(this).append(dropped.clone().removeAttr('style'));
dropped.remove();
}
});
.card{
width:80px;
height:80px;
color:#fff;
}
.right-list{
background-color: #B91646 !important;
}
.left-list{
background-color: #1F1D36 !important;
}
.form-check-input{
position:absolute;
top:0 !important;
right:0 !important;
left:0 !important;
bottom:0 !important;
margin:auto !important;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-6 d-flex flex-column align-items-center">
<div class="card left-list mb-3">
<input class="form-check-input" type="checkbox" value="" aria-label="...">
</div>
<div class="card left-list mb-3">
<input class="form-check-input" type="checkbox" value="" aria-label="...">
</div>
<div class="card left-list mb-3">
<input class="form-check-input" type="checkbox" value="" aria-label="...">
</div>
</div>
<div class="col-6" id="card-list">
<div class="card right-list mb-3">
<input class="form-check-input" type="checkbox" value="" aria-label="...">
</div>
<div class="card right-list mb-3">
<input class="form-check-input" type="checkbox" value="" aria-label="...">
</div>
<div class="card right-list mb-3">
<input class="form-check-input" type="checkbox" value="" aria-label="...">
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
Consider the following.
First, you cannot use
acceptin the way you attempted. Draggable should be initialized on it's own.I created a function yet you can do all this in the
dropcall back if you like. The function basically knows to look for Checked items and move those from the Source to the Target. It then removes any Drag styling and unchecks the items.If you like, you can use
helperto build an item that reflects all the checked items.See more: https://api.jqueryui.com/draggable/#option-helper
Update
Reference: jQuery ui.draggable event/status on revert