Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render markup in selector options text (fixes #51, fixes #50) #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions assets/aui.selector.publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
'Search and select': false
});

var utlityEl = $('<div/>');
function htmlDecode (value) {
if (typeof value === 'undefined') return '';
var decoded = utlityEl.html(value);
if (decoded.children().length) {
return value;
}
return decoded.text();
}

Symphony.Extensions.AssociationUISelector = function() {
var fields;

Expand Down Expand Up @@ -36,6 +46,7 @@
// Apply Selectize
storage.selectize({
preload: (limit === 0),
searchField: ['search'],
sortField: [{
field: 'text',
direction: 'asc'
Expand All @@ -55,6 +66,13 @@
onInitialize: function() {
var items = this.$control.find('.item');

$.each(this.options, function (key, option) {
var decodedText = htmlDecode(option.text);
var searchableText = utlityEl.html(decodedText).text();
option.text = decodedText;
option.search = searchableText;
});

initExistingItems(items, numeric);
},
onItemAdd: function(value, item) {
Expand Down Expand Up @@ -187,7 +205,8 @@
success: function(result) {
callback({
value: (numeric === true ? entryId : result.entry.value),
text: result.entry.value,
text: htmlDecode(result.entry.value),
search: utlityEl.html( htmlDecode(result.entry.value) ).text(),
section: result.entry.section,
link: result.entry.link,
id: entryId
Expand All @@ -214,7 +233,8 @@
$.each(result.entries, function(id, data) {
entries.push({
value: (numeric === true ? id : data.value),
text: data.value,
text: htmlDecode(data.value),
search: utlityEl.html( htmlDecode(data.value) ).text(),
section: data.section,
link: data.link,
id: id
Expand All @@ -227,11 +247,11 @@
};

var renderItem = function(data, escape) {
return '<div class="item" data-section-handle="' + data.section + '" data-link="' + data.link + '" data-entry-id="' + data.id + '"><span>' + data.text + '</span></div>';
return '<div class="item" data-section-handle="' + data.section + '" data-link="' + data.link + '" data-entry-id="' + data.id + '"><span>' + htmlDecode(data.text) + '</span></div>';
};

var renderOption = function(data, escape) {
return '<div class="option"><span>' + data.text + '</span></div>';
return '<div class="option"><span>' + htmlDecode(data.text) + '</span></div>';
};

var orderStart = function(selectize) {
Expand Down