Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

working with js in new quickCreate dialog in JIRA 5

pre-JIRA5, we had some javascript inserted that would manipulate UI elements. This new quickCreate dialog is throwing a curve that i cant seem to figure out. When the dialog is initially loaded, things are ok, js gets executed and UI elements can be accessed.

but when the project or issuetype is changed and the dialog is re-displayed, I cannot figure out how to execute any js AFTER the dialog is re-displayed. I can detect when the form (project/issue type) changes but anything executed here is executed BEFORE the dialog is re-displayed for the new project/issue type. Any suggestions?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted

you have to usebind event

JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
//your code here

and check this

this is correct answer @rambanam prasad

the reason why you cannot access the elements is because they are actually not present in DOM when the page loads and javascripts run. They are added to the DOM dynamically when the dialog actually appears.

So you must bind your js to NEW_CONTENT_ADDED event. It is fired whenever JIRA adds something to the DOM. In example when a Dialog is triggered.

as @rambanam prasad said, you have to wrap your js code inside new content added event.

great thanks!

@Lance, if my answer helped then accept it as a anwer so we can close it

this works but the binding stays intact after the the create-dialog goes away. I tried to bind to an element that would only exist in the dialog, such as id=create-issue-dialog but that doesnt seem to work. Any suggestions?

can you explian what's your requirement so i can help you

AJS.$(function() {
	// execute on popup
    	JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e, context, reason) {
		var $context = AJS.$(context);	
		// for dialog only
		if(reason == JIRA.CONTENT_ADDED_REASON.dialogReady){

			// get elements
			var submitButton = $context.find("#submit-button")[0];
			var inputElement = $context.find("#input-element")[0];

			inputElement.value = 'Hello World';

try this.

use $context.find("#elementId")[0]; to get an element by id and $context.find(".elementClass"); to find all elements by class.

Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

124 views 1 3
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you