RamonSmit / Nestable2

New pickup of Nestable!
Other
322 stars 147 forks source link

Bug: Insertion of duplicate items when trying to use 'add' with parent_id #84

Closed rkhom closed 7 years ago

rkhom commented 7 years ago

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.

rkhom commented 7 years ago

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');

pjona commented 7 years ago

@RomanKhomyshynets Thanks, great job!