Skip to content

Commit

Permalink
FIX TreeDropdownField doesnt change label on unselect
Browse files Browse the repository at this point in the history
  • Loading branch information
dhensby committed Jun 11, 2015
1 parent 38ca214 commit 6be0488
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
16 changes: 11 additions & 5 deletions forms/TreeDropdownField.php
Expand Up @@ -215,16 +215,21 @@ public function Field($properties = array()) {

Requirements::css(FRAMEWORK_DIR . '/thirdparty/jquery-ui-themes/smoothness/jquery-ui.css');
Requirements::css(FRAMEWORK_DIR . '/css/TreeDropdownField.css');


if($this->showSearch) {
$emptyTitle = _t('DropdownField.CHOOSESEARCH', '(Choose or Search)', 'start value of a dropdown');
} else {
$emptyTitle = _t('DropdownField.CHOOSE', '(Choose)', 'start value of a dropdown');
}

$record = $this->Value() ? $this->objectForKey($this->Value()) : null;
if($record instanceof ViewableData) {
$title = $record->obj($this->labelField)->forTemplate();
} elseif($record) {
$title = Convert::raw2xml($record->{$this->labelField});
} else if($this->showSearch) {
$title = _t('DropdownField.CHOOSESEARCH', '(Choose or Search)', 'start value of a dropdown');
} else {
$title = _t('DropdownField.CHOOSE', '(Choose)', 'start value of a dropdown');
}
else {
$title = $emptyTitle;
}

// TODO Implement for TreeMultiSelectField
Expand All @@ -237,6 +242,7 @@ public function Field($properties = array()) {
$properties,
array(
'Title' => $title,
'EmptyTitle' => $emptyTitle,
'Metadata' => ($metadata) ? Convert::raw2json($metadata) : null,
)
);
Expand Down
8 changes: 6 additions & 2 deletions javascript/TreeDropdownField.js
Expand Up @@ -154,17 +154,21 @@
var updateFn = function() {
var val = self.getValue();
if(val) {

var node = tree.find('*[data-id="' + val + '"]'),
title = node.children('a').find("span.jstree_pageicon")?node.children('a').find("span.item").html():null;
if(!title) title=(node.length > 0) ? tree.jstree('get_text', node[0]) : null;

if(title) {
self.setTitle(title);
self.data('title', title);
}
if(node) tree.jstree('select_node', node);
}
else {
self.setTitle(self.data('empty-title'));
self.removeData('title');
}
};

// Load the tree if its not already present
Expand Down
1 change: 1 addition & 0 deletions templates/forms/TreeDropdownField.ss
Expand Up @@ -2,6 +2,7 @@
class="TreeDropdownField <% if $extraClass %> $extraClass<% end_if %><% if $ShowSearch %> searchable<% end_if %>"
data-url-tree="$Link('tree')"
data-title="$Title.ATT"
data-empty-title="$EmptyTitle.ATT"
<% if $Description %>title="$Description.ATT"<% end_if %>
<% if $Metadata %>data-metadata="$Metadata.ATT"<% end_if %>>
<input id="$ID" type="hidden" name="$Name.ATT" value="$Value.ATT" />
Expand Down

0 comments on commit 6be0488

Please sign in to comment.