I'm using jquery ui drag and drop widgets for my application, and I'm facing some difficulties here.
On my droppable element, I fire a success message whenever a draggable is dropped on a droppable element using the drop
option.
Now, I want to fire an error message whenever a draggable element is rejected by a droppable one. I inserted the code for that to the accept
option (which is a function in this case), but the problem is that the accept function runs every time I go over a droppable element, and I want the message to be fired only when I drop the draggable element and it's rejected.
$slots.droppable({
accept: function(draggable) {
var valid = true;
if (!draggable.hasClass('draggable')) {
valid = false;
}
var _date = $(this).data('date');
var $thisDateSlots = $('.sort-panel-body-day-body-slot[data-date="' + _date + '"]');
$.each($thisDateSlots, function() {
if ($(this).data('item') == draggable.data('id')) {
console.log($(this).data('item'), draggable.data('id'));
valid = false;
}
});
return valid;
},
drop: function(event, ui) {
var dropped = ui.draggable;
dropped.data('slot', $(this).data('slot'));
dropped.data('date', $(this).data('date'));
stickToSlot(dropped, $(this).data('date'), $(this).data('slot'));
$(this).data('item', dropped.data('id'));
$(this).addClass('filled');
$(this).droppable('disable');
toastr.success('added successfuly');
initSlots();
},
out: function(event, ui) {
$(this).data('item', '');
$(this).removeClass('filled');
$(this).droppable('enable');
}
});
Any solutions for this?