jquery-sortable-lists icon indicating copy to clipboard operation
jquery-sortable-lists copied to clipboard

Add a new node

Open michaelbanet opened this issue 5 years ago • 8 comments

Is there any way to add a new list item dynamically? I attempted the following, but it causes the browser to crash from running out of memory:

$('#MappingEditor').append('<li id="New_Category"><div>New Category</div></li>').sortableLists(mappingOptions);

It seems to work for about a second before running out of memory. Is there an alternate way to re-instantiate sortableLists maybe?

michaelbanet avatar Jun 10 '20 20:06 michaelbanet

#MappingEditor ul object

Thanks for the quick response! If it helps, I threw everything into a CodePen

https://codepen.io/michaelbanet/pen/vYLLVqK

michaelbanet avatar Jun 10 '20 20:06 michaelbanet

I test it right now. This works without any problems:

        $('#add-test').on('click', function( e )
    	{
    		$('#sTree2').append( "<li id='add-test-li'><div>Add test</div></li>" );
    	});

The problem can be with maxLevels option which needs to have data-insideLevs and data-upperLevs set.

camohub avatar Jun 10 '20 20:06 camohub

You're right! I disabled maxLevels and it's working great! I'll leave that feature off for the time being (I guess I can use the isAllowed callback to limit level for now. Still early development)

michaelbanet avatar Jun 10 '20 20:06 michaelbanet

This works also with maxLevels.

	$('#add-test').on('click', function( e )
	{
		var item = $("<li id='add-test-li'><div>Add test</div></li>");
		item.data('insideLevels', 0);
		item.data('upperLevels', 0);
		$('#sTree2').append( item );
	});

I made maxLevels feature yesterday so if you will have a problem feel free to create an issue. I will fix it ASAP

camohub avatar Jun 10 '20 20:06 camohub

This works for me! If anything, maybe a small paragraph in your documentation would be super helpful for the next person.

Thanks!

michaelbanet avatar Jun 10 '20 20:06 michaelbanet

Do not close it for now. If somebody will search solution for this case.

camohub avatar Jun 10 '20 21:06 camohub

If someone is looking for a way to add an element to an existing empty node (with id:current_id_append in my example) Without appending the "hintwrap" variable, the new created element would not be draggable within the node

	$('#add-test').on('click', function( e )
	{
                var hintwrap = $("<ul id='s-l-hint-wrapper' style=\"display: block;\"></ul>");
                $('#'+current_id_append).append( hintwrap );
		var item = $("<li id='add-test-li'><div>Add test</div></li>");
		item.data('insideLevels', 0);
		item.data('upperLevels', 1);
		$('#'+current_id_append).children('ul').append( item );
                $('#'+current_id_append).children('ul').removeAttr( 'id' )
	});

I am still trying to figure out how to append the plus/minus icon to the div (with event)

michalgala avatar Sep 12 '20 20:09 michalgala

@michalgala What s the problem with plus/minus icons?

camohub avatar May 07 '21 19:05 camohub