Merge pull request #4272 from dhensby/pulls/tree-dropdown-fix

FIX TreeDropdownField doesnt change label on unselect
This commit is contained in:
Damian Mooyman 2015-06-15 11:36:45 +12:00
commit 6facb1bf5d
3 changed files with 18 additions and 7 deletions

View File

@ -216,15 +216,20 @@ class TreeDropdownField extends FormField {
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
@ -237,6 +242,7 @@ class TreeDropdownField extends FormField {
$properties,
array(
'Title' => $title,
'EmptyTitle' => $emptyTitle,
'Metadata' => ($metadata) ? Convert::raw2json($metadata) : null,
)
);

View File

@ -165,6 +165,10 @@
}
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

View File

@ -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" />