Forums

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

Upgraed to Jira 8.11 causes: TypeError: AJS.$(...).auiSelect2 is not a function

stadlerm September 7, 2020

Hi,

we have a working custom plugin, developed for Jira 8.5, which uses auiSelect2

Now, since upgrading to Jira 8.11, it no longer works, failing with the error:

Failed to run init function: AJS.$(...).auiSelect2 is not a function

The first line of my *.vm file is importing the select:

$webResourceManager.requireResourcesForContext("com.atlassian.auiplugin:aui-select2")

Followed by:

<script type="text/javascript">
AJS.toInit(function () {
console.log('Hello');

AJS.$("#select-one").auiSelect2();
AJS.$("#select-two").auiSelect2();

...
});
</script>

I've tried to look into some upgrad differences, but I can't see any guides for upgrading from jira 8.5

According to AJS.version the AUI version is 8.6.0

I have also tried adding 

<dependency>com.atlassian.auiplugin:aui-select2</dependency>

 to my plugin xml, but nothing changed

1 answer

1 accepted

0 votes
Answer accepted
stadlerm September 8, 2020

I managed to solve the problem. 

I tried moving the javascript into a resource, but there I noticed that the resource was never properly loaded. I tried:

  • Load resource directly ($webResourceManager.requireResource)
  • Load resource from custom context ($webResourceManager.requireResourcesForContext)
  • Using macros instead of $webResourceManager (#requireResourcesForContext)

But to no avail, the resources wouldn't load. This brought me to this topic: https://community.atlassian.com/t5/Answers-Developer-Questions/Velocity-don-t-load-resource/qaq-p/489704 which links this page: https://developer.atlassian.com/server/jira/platform/custom-fields-that-use-css-or-javascript-web-resources-in-jira-5-0/

Here it says: "In JIRA 5.1, calling requireResource() will not be supported for the other views of a custom field, either. Plugin authors are encouraged to put such web resoruces in the atl.general context instead of calling requireResource() from their velocity."

So it seems that the $webResourceManager isn't working properly, or I'm doing something wrong. But following the above, I could get it to work by simply adding a new web-resource with all dependencies to my atlassian-plugin.xml, using the atl.general context:

<web-resource key="magenta-applications-resources" name="tma-jira-plugin MagentaApplications Web Resources">
<dependency>com.atlassian.auiplugin:ajs</dependency>
<dependency>com.atlassian.auiplugin:jquery-ui-other</dependency>
<dependency>com.atlassian.auiplugin:aui-select2</dependency>

<context>atl.general</context>
</web-resource>

Now the auiselect2 works in both custom fields & in my webwork template

What is interesting, in my custom admin page, adding $webResourceManager.requireResource works, but there it is within "<head> ... </head>" so maybe that has something to do with it. 

However, I found that for custom fields or webwork actions, the <head> tags are ignored, so maybe it's something related to that.

Hope someone finds this useful

Suggest an answer

Log in or Sign up to answer