Bug: Insertion of duplicate items when trying to use 'add' with parent_id
rkhom opened this issue · 2 comments
Hi! There is a bug in Add function. When we try to add new item with setting parent_id, where parent item is non-leaf element, a new item appends to the parent item and to each its descendant.
For example, there is a code from your Demo-page:
https://jsfiddle.net/RomanKhomyshynets/4vogfw6o/1/
When we bind for "Add new item" button such actions
if(action === 'add-item') { var newItem = { "id": ++lastId, "content": "New Item " + lastId, "parent_id":2 }; $('#nestable').nestable('add', newItem); }
Nestable inserts "New item 13" two times - as a child of Item 2 and child of Item 5.
The problem is in row 244 of current version jquery.nestable.js
The solution is to change its code from tree = tree.find(listClassSelector);
onto
tree = tree.find(listClassSelector+':first');
@RomanKhomyshynets Thanks, great job!