clivezhg/select2-to-tree

Prevent 'Folders / Groups' from being selected

Nevario opened this issue · 2 comments

Firstly, a big thank-you for making this plugin, I'm very grateful!

Is there a way to disable the groups from being selected? I only want the normal items to be selectable?

For example, in the screenshot below, "Cameras" should not be selectable.

image

Is it possible?

Hi, I ran into the same issue as yourself.

As a workaround I did the following:

On the select2totree.js file locate the following code.

if ($(container).hasClass("non-leaf")) { return $.merge($('<span class="expand-collapse" onmouseup="expColMouseupHandler(event);"></span>'), $iteme); }

This code is responsible for joining together the label and the expand/collapse button. Notice that the expand/collapse button has an 'onmouseup' event that prevents default events from firing. What we want to do is create our own label which has this onmouseup event.

It should look something like the following:

if ($(container).hasClass("non-leaf")) { var $itemf = $("<span class='item-label' onmouseup='expColMouseupHandler(event)'></span>").append(label); return $.merge($('<span class="expand-collapse" onmouseup="expColMouseupHandler(event);"></span>'), $itemf); }

Hope that helps.

Hi @EarlMurray ,

A massive thank-you for taking the time to detail your solution to this issue.

I just tested and it works perfectly! Can't thank you enough!

Thanks,
Tim