camohub / jquery-sortable-lists

jQuery plugin to sorting lists also the tree structures.
MIT License
209 stars 60 forks source link

MaxLevels not working #64

Closed lulubytt closed 3 years ago

lulubytt commented 3 years ago

Hello @camohub! Thanks for a great plugin, this has saved me hours of dev work. :)

One issue though: the maxLevels options is not working. When I set it to a number, it stops nesting altogether. If I remove the maxLevels option (it defaults to false), it starts nesting again.

Please advise. Thanks!

camohub commented 3 years ago

I test it right now. It works as expected. What is wrong?

lulubytt commented 3 years ago

I am creating a dynamic menu. The user can drag and nest the menu items as they wish, but I want to allow only 2 levels of nesting. However, when I add the option {maxLevels : 2}, the nesting capabilities during the drag and drop are gone. It only allows me to change the order. I don't have any other options that might be conflicting.

Nesting works when MaxLevels is off. Nesting does not work when MaxLevels has a value. Just wondering if you can think of a reason this would happen?

camohub commented 3 years ago

It seems the problem is in your code. I test it and it works. Can you create an online example or Github repository?

lulubytt commented 3 years ago

Hi, so I did a couple of tests and I figured out that the plugin works well when you have static HTML laid out to begin with. But when you add content dynamically, like I'm trying to do, it fails. I made a simplified version of what I'm trying to do here so you can see for yourself:

https://github.com/lulubytt/jquery-sortable-lists-test

thanks!

camohub commented 3 years ago

You generate incorrect html structure. it has to be li>div not li>a

lulubytt commented 3 years ago

Thanks for taking a look. You're right, I tried first with the correct html structure: li>div but that didn't work either, so I removed the div to see what would happen. Neither work. I just changed it back to the correct structure and you can see in my repo that it still doesn't work. :/

camohub commented 3 years ago

Another problem is the maxLevels needs to add data-upperLevels and data-insideLevels attribute to the li element if you generate it. Although it seems the javascript demaged the data attribute and change upper L in the attribute name data-insideLevels to the lowercase. So plugin can not find the attribute.

camohub commented 3 years ago

Yes it seems it is a bug. It needs to be fixed. I am sorry.

lulubytt commented 3 years ago

No worries! I will be more than happy to make a donation to your account if you think you can get this fixed within the next week or so? Thanks!

camohub commented 3 years ago

Ok I can.

camohub commented 3 years ago

Hi, I fixed it. Try the newest version 2.4 and use minified version please.

Added item has to have data-upper-level="0" and data-inside-levels="0" attributes.

Let me know how it turned out.

lulubytt commented 3 years ago

Worked like a charm! Thanks so much :)