Do not delete the selected item
Closed this issue · 14 comments
Hi!
Version: 1.6
I'm trying to delete the selected item, but it does not delete.
My code is from the example:
visible.nestable('remove', id, function(){
console.log(id);
});
In this case, the ID of the element to be deleted is displayed in the console.
@s1lver You are sure you using the latest version? You need version 1.6.0. If yes, then you need provide example on jsfiddle.net.
@s1lver I using remove
method with this version and it works for me. Can you provide example on jsfiddle.net?
So if you put in JS part:
$('.dd').nestable('remove', 2, function(){
alert('test');
});
or
$('.dd').nestable('remove', 2);
then it works, so it's something with you code. Check console error in example you provided.
Hi there,
Agreed with @pjona that code from the example looks strange.
In my project remove methods works fine.
At me in the console deduces the identifier of deleted element.
In this case, the addition of the selected element to the neighboring sheet works successfully. Do not work only removal.
It seems there is a guess, but it is inaccurate. If the identifier is set static, then the deletion occurs.
Passing an identifier using the item.attr('id')
method does not lead to the desired result
But I see just errors.
First of all var named clicks is not defined and also I see u trying to use:
id = item.attr('id');
But you should use 'data-id' instead of 'id' attribute.
At me these attributes have identical values.
'data-id' = 'id'
<li class="dd-item js-dblclick" id="0" data-id="0" data-name="#">
<div class="dd-handle">#</div>
</li>
var item = $(e.currentTarget);
visible.nestable('remove', item.data('id'), function(){
console.log(item.data('id')); //Displayed - 0
});
Well...I've changed your code to:
var clicks = 0;
var delay = 500;
$('.dd').nestable({ /* config options */ });
$('body').on("mousedown", '.js-dblclick', function(e){
clicks++;
if (clicks === 1) {
timer = setTimeout(function() {
clicks = 0;
}, delay);
} else {
clearTimeout(timer);
var item = $(e.currentTarget),
id = item.attr('id');
//alert('test');
$('.dd').nestable('remove', id, function(){
console.log(id);
});
clicks = 0;
}
});
And now it displays in console id.
@pjona , could you please take a look at this.
I believe that method '_getItemById' just can't find an item when it is in the 'drag' mode.
And this is why we are not able to delete an item.
If set a timeout before deleting it works fine ;)
var clicks = 0;
var delay = 500;
$('.dd').nestable({ /* config options */ });
$('body').on("mousedown", '.js-dblclick', function(e){
clicks++;
if (clicks === 1) {
timer = setTimeout(function() {
clicks = 0;
}, delay);
} else {
clearTimeout(timer);
var item = $(e.currentTarget),
id = item.attr('id');
//alert('test');
setTimeout(function(){
$('.dd').nestable('remove', id, function(){
console.log(id);
});
}, 2000);
clicks = 0;
}
});
@s1lver ,
You can try this code to remove items, it should works for you ;)
setTimeout(function(){
$('.dd').nestable('remove', id, function(){
console.log(id);
});
}, 100);
@RomanBurunkov Yes, it works. Thank you!