select2 fix

This commit is contained in:
rulingcom 2025-06-06 17:43:59 +08:00
parent 9731fa83f3
commit 4e5882411b
1 changed files with 5 additions and 9 deletions

View File

@ -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 '<div>' + i.text + '</div>';
}, // Formats results in drop down
},
formatSelection: function(i) {
return '<div>' + i.text + '</div>';
}, //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);
</script>