Problem with AJS

Hello, I have created custom Issue Tab Panel with field, where I can add comment when Ill press my custom button “add comment”

In my VM template I have

AJS.$("#add-comment-button").click(function(e) {
        e.preventDefault();
        AJS.dialog2("#add-status-comment").show();
    });

This button works fine and window to write text appears, but… In other section in Issues --> Current Search —> Views (Detail Views), windows with space to write text dont appear when I click button “add comment”. It only appers in normal view of issue… Whats problem?

Try using the following format for your javascript and see if that works:

$(document).on("click", "#add-comment-button", function(e) {
        e.preventDefault();
        AJS.dialog2("#add-status-comment").show();
    });

I had the same problem where AJS wouldn’t work on certain pages.

it still does not work

Could you try this:

JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e, context, reason) {
        if (reason === JIRA.CONTENT_ADDED_REASON.pageLoad){
    $(document).on("click", "#add-comment-button", function(e) {
        e.preventDefault();
        AJS.dialog2("#add-status-comment").show();
    });
}

Still the same.
Hi, thanks for trying help me. I m working on it since 8 hours :confused: and still dont resolve this problem. Im tried ajax, loaded js function from external resources, adding from body tag etc…

Yeah I remember having the same issues when I started. You said you have your JS code in the velocity template right? You could try putting it in a seperate js file and call that file using the web resource manager.

You declare your web-resource in your atlassian-plugin.xml:

<web-resource key="resource-key" name="resource name">
    <resource type="download" name="cssfile.css" location="css/cssfile.css"/>
    <resource type="download" name="jsfile.js" location="js/jsfile.js"/>
  </web-resource>

and then you add the following to the head of your velocity template.

$webResourceManager.requireResource("groupId+artifactId:resource-key")

I changed my file and this still not works. In this case again are troubles with loading external resources.
for example:

  1. https://stackoverflow.com/questions/27571710/why-are-my-atlassian-confluence-requireresource-includes-not-working
  2. https://community.atlassian.com/t5/Answers-Developer-Questions/webResourceManager-requireResource-does-not-work-for-JIRA-6/qaq-p/473914
  3. https://community.atlassian.com/t5/Answers-Developer-Questions/requireResource-macro-not-working/qaq-p/534364

So I try use it include my VM file.