-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace doesn't appear to work correctly #69
Comments
Hi, I can try to help you but after weekend. Can you provide your example
on jsfiddle?
Włącz 7 lipca 2017 w 18:08:54, ijstanley (notifications@github.com) Napisał:
… Using the following code:
nestableElement.nestable('replace', {
id: replaceId,
name: name,
label: name,
slug: slug,
css_class: cssClass,
children: children
});
where children is similar to the following object:
[{
"css_class" : "",
"slug" : "/distributors/find",
"id" : 1472820817026,
"label" : "Find A Distributor",
"name" : "Find A Distributor"
}, {
"css_class" : "",
"slug" : "/distributors/become",
"id" : 1472820818729,
"label" : "Become A Distributor",
"name" : "Become A Distributor"
}, {
"css_class" : "",
"slug" : "/distributors/suggest",
"id" : 1472820819257,
"label" : "Suggest A Distributor",
"name" : "Suggest A Distributor"
}
]
It results in a new li being created inside the existing li, and the
expand/collapse doesn't display. The following is copied from Chrome:
<li data-name="Distributors" data-label="Distributors" data-id="1472139716346" data-url="/distributors" data-css_class="" data-is_open="true" class="dd-item">
<li data-id="1472139716346" data-name="Distributors" data-label="Distributors" data-url="/distributors" data-css_class="" class="dd-item">
<div class="dd-handle"><span class="dd-content">Distributors</span></div>
<div class="dd-options"><button class="btn btn-sm btn-success add" data-toggle="tooltip" data-placement="top" title="" data-original-title="Add"> <i class="fa fa-plus-square"></i></button><button class="btn btn-sm btn-info edit" data-toggle="tooltip" data-placement="top" title="" data-original-title="Edit"> <i class="fa fa-edit"></i></button><button class="btn btn-sm btn-danger delete" data-toggle="tooltip" data-placement="top" title="" data-original-title="Delete"> <i class="fa fa-trash"></i></button></div>
<ol class="dd-list">
<li data-css_class="" data-url="/distributors/find" data-id="1472820817026" data-label="Find A Distributor" data-name="Find A Distributor" class="dd-item">
<div class="dd-handle"><span class="dd-content">Find A Distributor</span></div>
<div class="dd-options"><button class="btn btn-sm btn-success add" data-toggle="tooltip" data-placement="top" title="" data-original-title="Add"> <i class="fa fa-plus-square"></i></button><button class="btn btn-sm btn-info edit" data-toggle="tooltip" data-placement="top" title="" data-original-title="Edit"> <i class="fa fa-edit"></i></button><button class="btn btn-sm btn-danger delete" data-toggle="tooltip" data-placement="top" title="" data-original-title="Delete"> <i class="fa fa-trash"></i></button></div>
</li>
<li data-css_class="" data-url="/distributors/become" data-id="1472820818729" data-label="Become A Distributor" data-name="Become A Distributor" class="dd-item">
<div class="dd-handle"><span class="dd-content">Become A Distributor</span></div>
<div class="dd-options"><button class="btn btn-sm btn-success add" data-toggle="tooltip" data-placement="top" title="" data-original-title="Add"> <i class="fa fa-plus-square"></i></button><button class="btn btn-sm btn-info edit" data-toggle="tooltip" data-placement="top" title="" data-original-title="Edit"> <i class="fa fa-edit"></i></button><button class="btn btn-sm btn-danger delete" data-toggle="tooltip" data-placement="top" title="" data-original-title="Delete"> <i class="fa fa-trash"></i></button></div>
</li>
<li data-css_class="" data-url="/distributors/suggest" data-id="1472820819257" data-label="Suggest A Distributor" data-name="Suggest A Distributor" class="dd-item">
<div class="dd-handle"><span class="dd-content">Suggest A Distributor</span></div>
<div class="dd-options"><button class="btn btn-sm btn-success add" data-toggle="tooltip" data-placement="top" title="" data-original-title="Add"> <i class="fa fa-plus-square"></i></button><button class="btn btn-sm btn-info edit" data-toggle="tooltip" data-placement="top" title="" data-original-title="Edit"> <i class="fa fa-edit"></i></button><button class="btn btn-sm btn-danger delete" data-toggle="tooltip" data-placement="top" title="" data-original-title="Delete"> <i class="fa fa-trash"></i></button></div>
</li>
</ol>
</li>
</li>
I'm using a custom itemRenderer:
function (item_attrs, content, children, options, item) {
var item_attrs_string = $.map(item_attrs, function (value, key) {
return ' ' + key + '="' + value + '"';
}).join(' ');
if (!item.label) {
setTimeout(function () {
$('[data-id=' + item.id + ']').find('.dd-handle').effect('highlight', {color: '#dff0d8'}, 2000);
}, 100);
}
var html = '<' + options.itemNodeName + item_attrs_string + '>';
html += '<' + options.handleNodeName + ' class="' + options.handleClass + '">';
html += '<' + options.contentNodeName + ' class="' + options.contentClass + '">';
html += content;
html += '</' + options.contentNodeName + '>';
html += '</' + options.handleNodeName + '><div class="dd-options">' +
"<button class='btn btn-sm btn-success add' data-toggle='tooltip' data-placement='top' title='' " +
"data-original-title='Add'> " +
"<i class='fa fa-plus-square'></i>" +
"</button>" +
"<button class='btn btn-sm btn-info edit' data-toggle='tooltip' data-placement='top' title='' " +
"data-original-title='Edit'> " +
"<i class='fa fa-edit'></i>" +
"</button>" +
"<button class='btn btn-sm btn-danger delete' data-toggle='tooltip' data-placement='top' title='' " +
"data-original-title='Delete'> " +
"<i class='fa fa-trash'></i>" +
"</button>" +
"</div>";
html += children;
html += '</' + options.itemNodeName + '>';
return html;
}
I can't see that I'm doing anything wrong here. I've inspected the
nestable source and I'd suggest the replace function should use
replaceWith() instead html():
replace: function (item)
{
var html = this._buildItem(item, this.options);
this._getItemById(item.id).replaceWith(html);
}
This appears to fix the HTML structure issue but the expand/collapse still
doesn't display. Are you able and available to help?
Many thanks
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#69>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAKa7N-tTfJkj_dZ59S7Yv_n2nmvR1-_ks5sLlgWgaJpZM4ORI9b>
.
|
Awesome, thank you. The fiddle is: https://jsfiddle.net/ijstanley/oaomxk5c/ Pressing the 'Perform Replace' button will show the issue, it replaces the 'Distributors' item. |
Having another look this morning, it seems the data doesn't get replaced either, until you move the item manually. Updated fiddle: https://jsfiddle.net/ijstanley/oaomxk5c/2/ |
It appears adding the line
|
Make sence for items with children. @pjona, should we use setParent at build function? |
@ijstanley @RomanBurunkov Thanks all for good suggestions, this commit should fixed the issue. I tested also when new item has more children - https://jsfiddle.net/Lykebpo9/1/ |
Using the following code:
where
children
is similar to the following object:It results in a new
li
being created inside the existingli
, and the expand/collapse doesn't display. The following is copied from Chrome:I'm using a custom
itemRenderer
:I can't see that I'm doing anything wrong here. I've inspected the nestable source and I'd suggest the replace function should use replaceWith() instead html():
This appears to fix the HTML structure issue but the expand/collapse still doesn't display. Are you able and available to help?
Many thanks
The text was updated successfully, but these errors were encountered: