Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

working with js in new quickCreate dialog in JIRA 5

Lance Wong July 30, 2013

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
RambanamP
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.
July 30, 2013

you have to usebind event

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

and check this

https://answers.atlassian.com/questions/47843/strange-javascript-problem-in-create-screen

Alexej Geldt
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.
July 30, 2013

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.

Lance Wong July 30, 2013

great thanks!

RambanamP
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.
July 31, 2013

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

Lance Wong July 31, 2013

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?

RambanamP
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.
August 1, 2013

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

1 vote
Alexej Geldt
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.
August 1, 2013
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.

TAGS
AUG Leaders

Atlassian Community Events