javascript for field behaviour

Vidula Kulkarni December 11, 2013

Hi, I tried adding the a script in the 'description' of my custom field (which is a dropdown). I edited the field configuration for the custom field.

When I create an issue and change the value of the custom dropdown, I dont get to see the alert that I added. Am I missing something?

The script I used is:

<script type="text/javascript">
jQuery(document).ready(function($) {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
callChangeFunction();
});
callChangeFunction();
function callChangeFunction(){
showHidField();
// dropdown custom field change function
$("#customfield_10300").change(function() {
showHidField();
});

}
function showHidField(){
//drop down field selected value
var dropDownFieldval = $.trim($("#customfield_10300 :selected").text());
alert(dropDownFieldval);
if(dropDownFieldval == 'MAS'){
alert('hello');

}
});

</script>

3 answers

1 accepted

0 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.
December 15, 2013

you did't closed second function, try with this script by opening create screen in new tab(right click on create issue button and click on open link in new tab), if it is working in this page and not working in popup then load it as webresource module in plugin as @Bharadwajsaid

&lt;script type="text/javascript"&gt;
jQuery(document).ready(function($) { 
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) { 
	callChangeFunction();
});
	callChangeFunction();
function callChangeFunction(){
		showHidField();
	// dropdown custom field change function
	$("#customfield_10300").change(function() {
		showHidField();
	});

}
function showHidField(){
	//drop down field selected value 
	var dropDownFieldval = $.trim($("#customfield_10300 :selected").text());
		alert(dropDownFieldval); 
	if(dropDownFieldval == 'MAS'){ 
		alert('hello');
	} 
}
});

&lt;/script&gt;

Vidula Kulkarni December 15, 2013

Thank you all. I want to set the value of a second dropdown depending on value selected in first dropdown. I could'nt get it to work and hence tried alert to check my first dropdown's value selected.

After using the script above, I resolved my problem. Thanks again.

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.
January 29, 2015

I am seeking to do same thing. I need to fetch elements, which are added to the document when a list box is used. For some reason JIRA.Events.NEW_CONTENT_ADDED is not triggered for me when i use a list-box. Instead it triggers just one time when the create issue dialog opens. (because the dialog adds content it triggers the change event, so the event itself is working). AJS.$(document).ready(function() { JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) { alert('more content added'); }); }); using a listbox on create-issue dialog does not trigger the alert.

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.
January 29, 2015

where you added your script? if you want to trigger on change event for list box then you need use same code as i specified in my answer!

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.
January 29, 2015

There is no event fired for me when i use list box with the code above. I am sure the script is on page and active. It is actually triggered when pop up dialog appears. But then it remains quite. Even though, more content is being added to the DOM when i use listbox and it populates its options. my script is registered as webresource in atlassian-plugin.xml

0 votes
Mizan
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.
December 15, 2013

What is the real task your script should do ?

0 votes
Bharadwaj Jannu
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.
December 15, 2013

is it going to second alert if you select MAS in dropdown?

you simply put dropDownFieldval in quotes and try.

Also you can refer this document from prasad https://answers.atlassian.com/questions/217176/show-hide-custom-field-depend-on-another-custom-field-value

Bharadwaj Jannu
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.
December 15, 2013

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events