diff --git a/app/views/admin/universal_tables/_entry_form.html.erb b/app/views/admin/universal_tables/_entry_form.html.erb index e4adeba..c305766 100644 --- a/app/views/admin/universal_tables/_entry_form.html.erb +++ b/app/views/admin/universal_tables/_entry_form.html.erb @@ -72,10 +72,6 @@ $("#universal_table_tags").select2({ $("#universal_table_tags").val(<%= raw(@entry.table_tags. collect { |tag| tag.id.to_s }) %>).trigger("change"); const preselectedData = $("#table_entry_related_entries").data('value'); - preselectedData.forEach(function(item) { - var option = new Option(item.text, item.id, true, true); - $('#table_entry_related_entries').append(option); - }); var select2Options = { maximumSelectionSize: 10, minimumResultsForSearch: Infinity, @@ -100,16 +96,16 @@ $("#universal_table_tags").select2({ cache: false }, formatResult: function(i) { - console.log(i) return '
' + i.text + '
'; - }, // Formats results in drop down + }, formatSelection: function(i) { return '
' + i.text + '
'; - }, //Formats result that is selected + }, escapeMarkup: function(m) { return m; - } // we do not want to escape markup since we are displaying html in results + } } - $("#table_entry_related_entries").select2(select2Options).trigger("change"); + $("#table_entry_related_entries").select2(select2Options); + $("#table_entry_related_entries").select2('data', preselectedData); \ No newline at end of file