Javascript in field description not working when first opening create issue dialog

Fabian Meier
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.
September 5, 2012

I am trying to use the following javascript to hide the javascript custom field and later add more functionality.

The strange thing is, it seems to work, but whenever I clear the browser cache and open the create issue dialog for the first time, it is not working.

<script type="text/javascript">

jQuery(document).ready(function($) {

    hideFields();
  
    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) { 
        hideFields();
    });

    function hideFields() {

        // Hide 'JavaScript' field
        jQuery("#customfield_10201").closest('div.field-group').hide();

    }

    });
</script>

I have read almost every single thread about the topic here on answers.atlassian.com but I cannot figure it out.

13 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Fabian Meier
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.
April 14, 2013

You either have to write your own web resource (plugin) or use the Live Fields functionality of the JJUPIN plugin from Kepler ROMInfo.

0 votes
meena bhujang August 29, 2013

Do we have to restart JIRA after adding javascript for custom field configuration?

I have added js for making a multi select custom field auto render. It is not working if I check in Search for that field after adding the javascript. Please guide. I have just started with JIRA

MattS
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 29, 2013

No you don't have to restart

TechnicalS February 9, 2014

We have the same issue

when I change the issuetype (so I change the fieldconfiguration because the other issuetype has another configuration) the javascript doesn t work.

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.
February 9, 2014

you need to load your javascript in a plugin as webresource module, check this

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

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.
September 5, 2012
0 votes
Harry Chan
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.
September 5, 2012

The way Javascript is handled has changed in JIRA 5.x and hence the new events you have to listen to. Please put the javascript in the required places. As you said this is working.

It's not that Jamie doesn't meantime his plugins. He just has an issue with JIRA 5.1 and inline editing vs the behaviour plugin. That is all.

0 votes
Fabian Meier
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.
September 5, 2012

I was actually talking about ScriptRunner not the Behaviors plugin. People keep filing bug reports, but he does not seem to have the time to reply.

Regarding this issue, but where should I put it? The javascript I put in the description field no longer gets executed for the current issue type, but for the next one I choose.

0 votes
Fabian Meier
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.
September 5, 2012

I really don't want to use another plugin for this and Jamie seems to be quite busy at the moment and does not maintain his plugins as well as he did in the past.

I would really prefer to figure out why this worked on JIRA 4.4.5 but is no longer working for JIRA 5.x

0 votes
Harry Chan
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.
September 5, 2012

Hi, that's correct. Since you put it in the field configuration, it is part of the field configuration scheme. This is per issue type / project.

0 votes
Fabian Meier
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.
September 5, 2012

But the actual problem here is, that the code does not work if the preselected issue type is not setting binding the event JIRA.Events.NEW_CONTENT_ADDED.

We have 10 different issue types, but I only need to use it for 4, that means I have to configure it for all or for none =(

0 votes
Fabian Meier
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.
September 5, 2012

Ok, I might have found the cause here:

If the preselected issue type does not have the javascript associated, then the whole thing does not work because the code never gets executed.

0 votes
Harry Chan
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.
September 5, 2012

You can add it globally instead in the description of the custom field and not in the field configuration. Not sure if it'd be desired though as that would apply for everything.

The other idea is that the behaviour plugin does this out of the box.

0 votes
Harry Chan
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.
September 5, 2012

Simply put this in every description within a field configuration that needs this? You can create separate field configurations and map it to different issue types.

0 votes
Fabian Meier
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.
September 5, 2012

How can I make it run the javascript for all issue types but have separate actions per issue type? I don't want to write a plugin. Would a combination of announcement banner and field configurations do?

0 votes
Harry Chan
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.
September 5, 2012

Hi, jQuery doesn't exist. Atlassian doesn't allow it. What I do is call AJS.$ instead. You need to prefix the jQuery calls with AJS.

Fabian Meier
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.
September 5, 2012

That's not it. jQuery works just fine for me, but even with the following modifications you suggested it is still the same. When I first open the dialog, the field is rendered. If I close it and open it again then it disappears.

<script type="text/javascript">

AJS.$(document).ready(function($) {

	runJS();
	
	JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {   
        runJS();
	});

	function runJS() {

		// Hide 'JavaScript' field
		AJS.$("#customfield_10201").closest('div.field-group').hide();

	}

    });
</script>

Harry Chan
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.
September 5, 2012

It's AJS.$(function($) {...

I would check in Firebug or Chrome or any other developer tool you are using to see what Javascript error appears.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events