Hi
im using confluence cloud and i wanna select multiple labels for auiselect2 using ajax request.
I can get all spaceLabels from wiki/rest/api/space/FS?expand=metadata.labels
here is my function code
function select2_labels(input) {
input.auiSelect2({
width: 'value',
minimumInputLength: 1,
multiple: true,
tags: true,
tokenSeparators: [',', ' '],
createTag: function (params) {
var term = $.trim(params.term);
if (term === '') {
return null;
}
return {
id: term,
text: term,
newTag: true // add additional parameters
}
},
//REST end-point // make the control a multi-select
ajax: {
url: function (params) {
return (
'rest/api/space/FS?expand=metadata.labels?name~"' +
params +
'"'
);
},
type: "GET",
dataType: "json",
cache: true,
transport: function (params, success, failure) {
AP.request({
url: params.url,
type: "GET",
contentType: "application/json",
success: function (data) {
params.data = JSON.parse(data);
params.success(params.data);
},
});
},
// parse data from the server into form select2 expects
data: function data(term) {
return {
cql: "name~'" + term + "*'",
};
},
// parse data from the server into form select2 expects
results: function (data) {
const results = [];
data.results.forEach(function makeResults(element, index) {
results.push({
label: element.label,
});
});
return {
results: results,
};
},
},
initSelection: function (element, callback, label_list) {
callback(label_list)
},
id: function id(user) {
if (label.label == undefined) {
return label.id;
} else {
return label.label.id;
}
},
// define how selected element should look like
formatSelection: function formatSelection(label) {
if (input != "") {
input.parent().find('.list-creators').css("border-bottom", "1px solid lightgray");
input.append('<li creator_id="' + label.label.id + '" class="aui-dropdown2-checkbox interactive status-check list-creator-filter aui-dropdown2-interactive" resolved="" aria-checked="false" tabindex="0"><div class="search-creator-option-timeline"><div class="search-creator-option"><div class="search-creators"><div class="search-creator-name"><span class="search-profil-creator"><a href="#" target="_blank" class="confluence-userlink">' + label.label.name + '</a></span></div></div></div></div></li>');
}
return (
'<span style="display: flex;align-items: center" class="sp-dropdown-user-selector-li" id=' +
label.label.id +
">" +
Select2.util.escapeMarkup(label.label.name) +
"</span>"
);
},```