Skip to content

Commit

Permalink
Introduced parentIncludesChilds option. If activated, selecting a par…
Browse files Browse the repository at this point in the history
…ent implicitely selects all children (checks and disables their checkbox). Only makes a difference in multi select mode.
  • Loading branch information
crazy4chrissi committed Nov 28, 2018
1 parent 128109d commit 5c9f398
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ ComboTree is a jQuery Plugin which is a combobox item with tree structured data
- icontains.js (filtering. It can be found in repository)

##Configurations:
- isMultiple: {True/False} | decide if it is multiple selection behaviour or single
- source: {JSON Data Array} | takes source of combobox dropdown menu as a JSON array.
- expandAll: {True/False} | Whether to expand the tree or not
- isMultiple: {True/False} | Whether it is multiple selection behaviour or single.
- source: {JSON Data Array} | Takes source of combobox dropdown menu as a JSON array (see Sample).
- expandAll: {True/False} | Whether to expand the tree or not.
- parentIncludesChilds: {True/False} | Whether selecting a parent implicitely means childs are selected as well and thus cannot be selected independently (only for multi select).

##Usage

Expand All @@ -26,13 +27,19 @@ There should be an input element to apply and a JSON Data source.
comboTree1 = $('#justAnInputBox').comboTree({
source : SampleJSONData,
isMultiple: true,
expandAll: false
expandAll: false,
parentIncludesChilds: true
});

// Array, One title/id, or False value return
var selectedTitles = comboTree1.getSelectedItemsTitle();
var selectedIds = comboTree1.getSelectedItemsId();

// copy the selected IDs into a hidden input element on submit
$('form').submit(function(event) {
$('<input>').attr({ type:'hidden', name: 'justAnInputBox_ids'}).val(comboTree1.getSelectedItemsId()).appendTo('form');
});

// To remove plugin
comboTree1.destroy();

Expand Down
1 change: 1 addition & 0 deletions Sample.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ <h3>Configurations:</h3>
<li><strong>source:</strong> {JSON OBJECT} It can take JSON data object</li>
<li><strong>isMultiple:</strong> {True/False} </li>
<li><strong>expandAll:</strong> {True/False} </li>
<li><strong>parentIncludesChilds:</strong> {True/False}</li>
</ul>
</p>
<br /><br />
Expand Down
10 changes: 10 additions & 0 deletions comboTreePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
source: [],
isMultiple: false,
expandAll: false,
parentIncludesChilds: true
};

// The actual plugin constructor
Expand Down Expand Up @@ -260,6 +261,8 @@
this.closeDropDownMenu();
};
ComboTree.prototype.multiItemClick = function (ctItem) {
if($(ctItem).find("input").prop('disabled'))
return;
this._selectedItem = {
id: $(ctItem).attr("data-id"),
title: $(ctItem).text()
Expand All @@ -269,10 +272,17 @@
if (index){
this._selectedItems.splice(parseInt(index), 1);
$(ctItem).find("input").prop('checked', false);
if(this.options.parentIncludesChilds)
$(ctItem).next('ul').find(':checkbox').prop("disabled", false).prop('checked', false);
}
else {
this._selectedItems.push(this._selectedItem);
$(ctItem).find("input").prop('checked', true);
if(this.options.parentIncludesChilds) {
$(ctItem).next('ul').find(':checked').parent().click();
$(ctItem).next('ul').find(':checkbox').prop("checked", true);
$(ctItem).next('ul').find(':checkbox').prop("disabled", true);
}
}

this.refreshInputVal();
Expand Down

0 comments on commit 5c9f398

Please sign in to comment.