Permalink
Browse files

BUGFIX get TreeMultiselectField working with an array of items, rathe…

…r than a relation. (from r100525)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@105594 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
1 parent 81d26a2 commit 4e87fb5713d26d7513829737984d2aef2bc969dd @chillu chillu committed May 25, 2010
Showing with 21 additions and 21 deletions.
  1. +16 −17 forms/TreeMultiselectField.php
  2. +5 −4 javascript/TreeSelectorField.js
@@ -29,12 +29,21 @@ function getItems() {
return $items;
// Otherwise, look data up from the linked relation
+ } if($this->value != 'unchanged' && is_string($this->value)) {
+ $items = new DataObjectSet();
+ $ids = explode(',', $this->value);
+ foreach($ids as $id) {
+ if(!is_numeric($id)) continue;
+ $item = DataObject::get_by_id($this->sourceObject, $id);
+ if($item) $items->push($item);
+ }
+ return $items;
} else if($this->form) {
$fieldName = $this->name;
$record = $this->form->getRecord();
if(is_object($record) && $record->hasMethod($fieldName))
return $record->$fieldName();
- }
+ }
}
/**
* We overwrite the field attribute to add our hidden fields, as this
@@ -54,25 +63,15 @@ function Field() {
Requirements::javascript(SAPPHIRE_DIR . '/javascript/LeftAndMain.js');
Requirements::javascript(SAPPHIRE_DIR . "/javascript/TreeSelectorField.js");
- // Any field values have priority over the relation getters
- if($this->value) {
- $items = new DataObjectSet();
- $ids = explode(',', $this->value);
- foreach($ids as $id) {
- if(!is_numeric($id)) continue;
-
- $item = DataObject::get_by_id($this->sourceObject, $id);
- if($item) $items->push($item);
- }
- } else {
- $items = $this->getItems();
- }
- if($items && $items->Count()) {
- foreach($items as $item) {
- $titleArray[] =$item->Title;
+ $items = $this->getItems();
+
+ if($items && count($items)) {
+ foreach($items as $id => $item) {
+ $titleArray[] = $item->Title;
$idArray[] = $item->ID;
}
+
if(isset($titleArray)) {
$itemList = implode(", ", $titleArray);
$value = implode(",", $idArray);
@@ -209,8 +209,6 @@ TreeDropdownField.prototype = {
* Called once the tree has been delivered from ajax
*/
newTreeReady: function (response, keepTreeHidden) {
- // alert('newTreeReady');
-
this.itemTree.innerHTML = response.responseText;
// HACK IE6: see http://www.hedgerwow.com/360/bugs/css-select-free.html
this.itemTree.appendChild(document.createElement('iframe'));
@@ -378,10 +376,13 @@ TreeMultiselectField.prototype = {
var selectedItems = this.inputTag.value.split(/ *, */);
var i, isSelected = {};
for(i=0;i<selectedItems.length;i++) isSelected[selectedItems[i]] = true;
-
+
var allNodes = this.tree.getElementsByTagName('li');
+
for(i=0;i<allNodes.length;i++) {
- if(isSelected[allNodes[i].getIdx()]) {
+ allNodes[i].id.match(/([^-]+)-(\d+)$/);
+ var idx = RegExp.$2
+ if(isSelected[idx]) {
this.tree.selectNode(allNodes[i]);
allNodes[i].expose();
}

0 comments on commit 4e87fb5

Please sign in to comment.