BUGFIX: Update hidden field of TreeMultiselectField as soon as checkboxes are clicked. Related to http://mingle.silverstripe.com/projects/air_nz_cms_enhancements/cards/139 (from r88935)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@89202 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-10-15 22:38:42 +00:00
parent e36798bc9b
commit 9809c0164f

View File

@ -263,6 +263,7 @@ TreeMultiselectField.prototype = {
newTreeReady: function (response) {
this.TreeDropdownField.newTreeReady(response);
MultiselectTree.create(this.tree);
this.tree.options.onselect = this.updateVal.bind(this);
// Select the appropriate items
var selectedItems = this.inputTag.value.split(/ *, */);
@ -272,14 +273,20 @@ TreeMultiselectField.prototype = {
var allNodes = this.tree.getElementsByTagName('li');
for(i=0;i<allNodes.length;i++) {
if(isSelected[allNodes[i].getIdx()]) {
this.tree.multiselect_handleSelectionChange(allNodes[i]);
this.tree.selectNode(allNodes[i]);
}
}
},
hideTree: function() {
this.TreeDropdownField.hideTree();
if(this.tree) this.updateVal();
},
/**
* Update the inputTag and humanItems from the currently selected nodes.
*/
updateVal: function() {
var internalVal = humanVal = "";
for(i in this.tree.selectedNodes) {
@ -289,8 +296,26 @@ TreeMultiselectField.prototype = {
this.inputTag.value = internalVal;
this.humanItems.innerHTML = humanVal;
}
},
updateTreeLabel: function() {
var treeNode;
if(this.inputTag.value) {
var innerHTML = '';
var selectedItems = this.inputTag.value.split(/ *, */);
for(i=0;i<selectedItems.length;i++) {
if(treeNode = $('selector-' + this.inputTag.name + '-' + selectedItems[i])) {
innerHTML += (innerHTML?', ':'') + treeNode.getTitle();
} else {
innerHTML += selectedItems[i];
}
}
this.humanItems.innerHTML = innerHTML;
} else {
this.humanItems.innerHTML = '(Choose)';
}
}
}