Fix issue where TreeDropdownField loses value on show/hide

Fixes https://github.com/silverstripe/silverstripe-cms/issues/1157
This commit is contained in:
Daniel Hensby 2015-01-27 11:37:10 +00:00 committed by Daniel Hensby
parent efb1eb5886
commit 6103d66116
3 changed files with 8 additions and 9 deletions

View File

@ -213,8 +213,7 @@ class TreeDropdownField extends FormField {
$properties, $properties,
array( array(
'Title' => $title, 'Title' => $title,
'TitleURLEncoded' => rawurlencode($title), 'Metadata' => ($metadata) ? Convert::raw2json($metadata) : null,
'Metadata' => ($metadata) ? Convert::raw2att(Convert::raw2json($metadata)) : null
) )
); );

View File

@ -56,7 +56,7 @@
var linkTitle = strings.openLink; var linkTitle = strings.openLink;
if(linkTitle) this.find("treedropdownfield-toggle-panel-link a").attr('title', linkTitle); if(linkTitle) this.find("treedropdownfield-toggle-panel-link a").attr('title', linkTitle);
if(this.data('title')) this.setTitle(decodeURIComponent(this.data('title'))); if(this.data('title')) this.setTitle(this.data('title'));
this.getPanel().hide(); this.getPanel().hide();
this._super(); this._super();
@ -138,10 +138,10 @@
this[this.getPanel().is(':visible') ? 'closePanel' : 'openPanel'](); this[this.getPanel().is(':visible') ? 'closePanel' : 'openPanel']();
}, },
setTitle: function(title) { setTitle: function(title) {
if(!title) title = strings.fieldTitle; title = title || this.data('title') || strings.fieldTitle;
this.find('.treedropdownfield-title').html(title); this.find('.treedropdownfield-title').html(title);
this.data('title', encodeURIComponent(title)); // separate view from storage (important for search cancellation) this.data('title', title); // separate view from storage (important for search cancellation)
}, },
getTitle: function() { getTitle: function() {
return this.find('.treedropdownfield-title').text(); return this.find('.treedropdownfield-title').text();

View File

@ -1,8 +1,8 @@
<div id="TreeDropdownField_$ID" <div id="TreeDropdownField_$ID"
class="TreeDropdownField single<% if extraClass %> $extraClass<% end_if %><% if ShowSearch %> searchable<% end_if %>" class="TreeDropdownField single<% if extraClass %> $extraClass<% end_if %><% if ShowSearch %> searchable<% end_if %>"
data-url-tree="$Link(tree)" data-url-tree="$Link(tree)"
data-title="$TitleURLEncoded" data-title="$Title.ATT"
<% if $Description %>title="$Description"<% end_if %> <% if $Description %>title="$Description.ATT"<% end_if %>
<% if $Metadata %>data-metadata="$Metadata"<% end_if %>> <% if $Metadata %>data-metadata="$Metadata.ATT"<% end_if %>>
<input id="$ID" type="hidden" name="$Name" value="$Value" /> <input id="$ID" type="hidden" name="$Name.ATT" value="$Value.ATT" />
</div> </div>