AUI select2 - wrong appearance applying with Scriptrunner

Hi colleagues,
same issue as of this post of 2017; AUI Select 2 not working properly
Tried this code even but the result appears to be the same as the screenshot attached.
Console provides an error like: AJS.MultiSelect is not a constructor…
Presumably, there is something wrong of AUI settings on the server? Confuence v7.2.0, AJS.version 8.3.5.
I tried the code of select2 AUI web page (AUI Select2 - AUI Documentation) prior to this post, but provided same result.
select2_wrong

All aui class based forms do not work out for me.

Appreciate any support of what is going wrong.

Thanks in advance.

Hi @tw1,

Are you building your own page in Confluence, or are you trying to extend an existing page?

How are you loading the front-end code for AUI? Are you requiring the web-resources for AUI’s forms and select 2 patterns?

Somewhere in your app’s Java code, you will need to make a call similar to the following (taken from this Confluence docs page on web resources):

@Named
public MyServlet extends HttpServlet {
    @ConfluenceImport
    private PageBuilderService pageBuilderService;

    @Inject
    public MyServlet(PageBuilderService pageBuilderService) {
        this.pageBuilderService = pageBuilderService;
    }

    // call this either in your page action or your web fragment renderer.
    // in either case, call it before your template is rendered.
    private void requireMyResources() {
        pageBuilderService.assembler().resources().requireWebResource("com.atlassian.auiplugin:aui-select2");
        pageBuilderService.assembler().resources().requireWebResource("com.atlassian.auiplugin:aui-forms");
    }
}

If you have your own JS and CSS to apply to your UI, instead of requiring the AUI resources directly from your Java code, you might instead create your own web-resource and require that instead:

In your atlassian-plugin.xml file:

<web-resource key="my-feature-resources">
  <dependency>com.atlassian.auiplugin:aui-select2</dependency>
  <dependency>com.atlassian.auiplugin:aui-forms</dependency>
</web-resource>

In your Java code, change the requireMyResources method to call this instead:

pageBuilderService.assembler().resources().requireWebResource("my.plugin.key:my-feature-resources");

Hope that helps!

Hi daz,
thanks a lot for real fast reply.

Well, your question regarding loading… I forgot to mention. Via Adaptavist Scriptrunner for Confluence. Creating a scripted macro, which is going to load the J + JS code.
I would rather refer to the atlassian-plugin.xml, which honestly does not exist yet on server. This is most probably my issue.
Which way might be the better one, resources or xml file?
Quite new, as I’ve been working w/ Jira before.

Thanks again for help.

Ah, I’m not familiar with ScriptRunner’s capabilities for defining and loading UI code. Perhaps @jmort or @dluksza could chime in and offer assistance on that front?

Hi @tw1,

I’m one of the developers working on the ScriptRunner team.

In order to limit amount of data send to client and seed up page load times, the Custom Macros doesn’t include any of the additional AUI dependencies. Select2 is one of those dependencies that are not available by default.

As @daz already mentioned you need require select2 on your own. In case of ScriptRunner Script Macros you need to add:

import com.atlassian.webresource.api.assembler.PageBuilderService
import com.atlassian.sal.api.component.ComponentLocator

def pageBuilderService = ComponentLocator.getComponent(PageBuilderService)

pageBuilderService.assembler().resources().requireWebResource("com.atlassian.auiplugin:aui-select2");

to the Macro code configuration option. This code ensures that select2 will be loaded before client side code from Custom Macro will be executed.

Hope this helps, let me know if you have any further questions.

1 Like

Hi @dluksza,

thanks a lot.
It perfectly works out now. Really, like posted in the initially mentioned link of mine, of AUI v8.3.5.

The question, did I miss any web post or is it professional developer knowledge?
Thanks anyway to @daz and to you for really fast reply and resolution.
Very much appreciate.

Since I am continuing to work w/ Scriptrunner I may have to address further inquiries directly…

Thanks again.