How to allow selection of parent node when children does not exist


#1
   <select class="js-example-responsive" multiple="multiple" style="width: 75%" id="cboImageFolderNames" name="cboImageFolderNames" ></select>

The JSON:
var folder = [
{
“text”: “Group 1”,
“children”: [
{
“id”: 1,
“text”: “Option 1.1”
},
{
“id”: 2,
“text”: “Option 1.2”
}
]
},
{
“text”: “Group 2”,
“children”: [
{
“id”: 3,
“text”: “Option 2.1”
}
]
},
{
“text”: “Group 3”
}
];

I want to select the children as well as parent node (only if there are no children’s in it). With respect to above JSON I can select “Option 1.1”, “Option 2.1” but I can not select “Group 1” and “Group 2” as they contain children which is fine. But if they do not contain children can I select them too. I want to select “Option 1.1”, “Option 2.1” and “Group 3”.

Is this possible, is there any option to achieve this?


#2

For an item to be selectable in a Select2, it must have an id value. If you give your “Group 3” item an id property, that should make it selectable.