Skip to content
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

Add a new node #57

Open
michaelbanet opened this issue Jun 10, 2020 · 8 comments
Open

Add a new node #57

michaelbanet opened this issue Jun 10, 2020 · 8 comments

Comments

@michaelbanet
Copy link

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
Copy link
Author

#MappingEditor ul object

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

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

@camohub
Copy link
Owner

camohub commented Jun 10, 2020

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.

@michaelbanet
Copy link
Author

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)

@camohub
Copy link
Owner

camohub commented Jun 10, 2020

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

@michaelbanet
Copy link
Author

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

Thanks!

@camohub camohub reopened this Jun 10, 2020
@camohub
Copy link
Owner

camohub commented Jun 10, 2020

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

@michalgala
Copy link

michalgala commented Sep 12, 2020

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)

@camohub
Copy link
Owner

camohub commented May 7, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants