Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Use aui-select2 in gadget's configuration screen

Michael Kornatzki
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 25, 2024

Hi,

i have created a gadget with a multiselect list in the gadget's configuration screen.
Now I want to use aui-select2, but I can't find the right place to specify it.
When I click on the button to edit the gadget-configuration, there is no event (or i can't find it).
In Javascript simply use

AJS.$(document).ready(function() { 
AJS.$(“#dashboards”).auiSelect2();
}

does not work.
Probably because the configuration page is not displayed when loading (display: none) 

Thanks in advance
Michael

1 answer

0 votes
Tuncay Senturk _Snapbytes_
Community Champion
October 1, 2024

Hi @Michael Kornatzki 

I know gadgets and JavaScript in XML can be a pain in the neck. I usually use the following approach to dynamically retrieve select options via REST and fill the select component accordingly. I hope that helps.

 

{
userpref: "mySelect",
id: "mySelectDiv",
label: "Label",
type: "callbackBuilder",
callback: function (parentDiv) {
var componentSelect = AJS.$("<select/>").attr({
id: "mySelect",
name: "mySelect",
class: "select"
});
// call your rest and fill select component with options
AJS.$.get("__ATLASSIAN_BASE_URL__/rest_service", function (data) {
AJS.$(data).each(function () {
var option = AJS.$("<option>").attr('value', this.value).text(this.label);
if (gadget.getPref("mySelect") == this.value) {
option.attr("selected", "true");
}
componentSelect.append(option);
});
});
parentDiv.append(componentSelect);
}
},

I also used select2(), but I can't say it is the best approach.

Best

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events