Changing issue type is not affecting javascript for custom field

Aditya kumar Madhira October 2, 2013

Hi

I have written a java script effecting textbox based on selected list. Working fine for default issue type and not effecting if i change issue type is changed.

My screen has project , issue types, select list and textbox.

Example if I open create issue --> select issue type bug - java script will fire. Now if I change other issue type -'discussion' --java script want fire.

Note - custom field values are same.

Any one can help me -

My script-

<script type="text/javascript">
priority = document.getElementById('customfield_807401');
if (priority) {
	target = document.getElementById('customfield_807418');
	if (priority.value != 10836)
		target.style.display='none';
	priority.onchange=function() {
		if (this.value == 10836) {
			target.style.display = '';
			target.value="enter message here";
		} else {
			target.style.display='none';
		}
	}

}
</script>

4 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.
October 2, 2013

try with this script

<script type="text/javascript">  
jQuery(document).ready(function($) {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
		callFunction();
	});
		callFunction();
function callFunction(){
		hideShowField();
	$('#customfield_807401').change(function(){	
		hideShowField();
	});
}

function hideShowField(){
var priorityValue=$('#customfield_807401').val();
	if(priorityValue == '10836'){
		//to show field
		$('#customfield_807418').closest('div.field-group').show();
		$('#customfield_807418').val("enter message here");
	}else{
		$('#customfield_807418').closest('div.field-group').hide();
	}
}
});
</script>

if you want to work this on create scren then you have to use webresource module.

did you gone through link which i have posted on my previous answer( i got same problem when we migrated to jira 5.x)

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.
October 2, 2013

make your javascript run as web-resource module and it might work.

Although I have solved the javascript problems loading as web-resource module.

Aditya kumar Madhira October 2, 2013
Means how bhatadwaj
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.
October 2, 2013

you go through https://developer.atlassian.com/display/JIRADEV/Web+Resource+Plugin+Module

<strong>Modify the above formed default atlassian-plugin.xml as</strong>
<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
    <plugin-info>
        <description>${project.description}</description>
        <version>${project.version}</version>
        <vendor name="${project.organization.name}" url="${project.organization.url}" />
        <param name="plugin-icon">images/pluginIcon.png</param>
        <param name="plugin-logo">images/pluginLogo.png</param>
    </plugin-info>
     
    <!-- add our web resources -->
    <web-resource key="yourmodulekey" name="your Web Resource module name">
        <dependency>com.atlassian.auiplugin:ajs</dependency>
          
         
        <resource type="download" name="yourfilename.js" location="{location of yourfilename.js}"/>
         
        <context>atl.general</context>
    </web-resource>
     
      
</atlassian-plugin>

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.
October 2, 2013

what is the jira version you are using???

Aditya kumar Madhira October 2, 2013
5.2 version. I am writing JavaScript in description of custom field. How to use web resource?
0 votes
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.
October 2, 2013

what is the jira version?

if you are using jira 5.0 and later then check this

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

0 votes
Jobin Kuruvilla [Adaptavist]
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.
October 2, 2013

Are you sure the javascript is loaded on screen when the new issuetype (discussion) is selected? Maybe you haven't added the javascript in the description of the field in the corresponding field configuration?

Aditya kumar Madhira October 2, 2013
@jobin i added in field configuration

Suggest an answer

Log in or Sign up to answer