Custom autocomplete multi select in MacroBrowser


I'm currently working on a macro plugin for Confluence. As part of this, I need to write some custom autocomplete parameter fields for the MacroBrowser. I have managed to create a Select2 field with a custom AJAX call to dynamically fetch options. Selecting and saving the chosen parameters works just fine, but if the macro is edited on a later date, chosen options are not displayed in the select field. They are selected however, as they cannot be selected again and will remain set, if new options are added.

This is the code I have thus far (using labels as an example):

var jsOverrides = {
"fields" : {
"string" : function(params, options){

if (params && != "labels") {
return AJS.MacroBrowser.ParameterFields["string"](params, options);

var paramDiv = $(Confluence.Templates.MacroBrowser.macroParameter());
var input = $("input", paramDiv);
var field = AJS.MacroBrowser.Field(paramDiv, input, options);

minimumInputLength: 1,
multiple: true,
ajax: {
url: AJS.params.baseUrl + "/labels/autocompletelabel.action",
dataType: 'json',
type: 'GET',
data: function(query) {
return {
query: query,
maxResults: 3
results: function(data, params) {

var results = [];
var matches = data.contentNameMatches;
for (var i = 0; i < matches[0].length; ++i) {
var match = matches[0][i];
return {
results: results

return field;

AJS.MacroBrowser.setMacroJsOverride("autocomplete-test", jsOverrides);

0 answers

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Friday in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

277 views 11 10
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you