JavaScript to Hide/Show Custom Field

I have a javascript at a custom fields to hide/show the field based on another field value.
It works fine when I create an issue.
The problem is when I change the project or the issue type. When I do this it seems that I don't have a javascript.
One of the javascripts that I use is:
<script>
checkbox_11106_1 = document.getElementById('customfield_11106-1'); //New - Yes
checkbox_11106_2 = document.getElementById('customfield_11106-2'); //New - No

if (!checkbox_11106_1.checked){
	AJS.$("#customfield_11118").closest('div.field-group').show();
}
if (!checkbox_11106_2.checked){
	AJS.$("#customfield_11118").closest('div.field-group').hide();
	document.getElementById('customfield_11118').value = '';
}

checkbox_11106_1.onclick=function(){
	if (checkbox_11106_1.checked){
		AJS.$("#customfield_11118").closest('div.field-group').hide();
		document.getElementById('customfield_11118').value = '';
	}
};
checkbox_11106_2.onclick=function(){
	if (checkbox_11106_2.checked){
		AJS.$("#customfield_11118").closest('div.field-group').show();
	}
};
</script>

How can I resolve this problem?

4 answers

1 accepted

This widget could not be displayed.

Now it works. I'm using this script at the custom field

<script>
function newField(){
		if (document.getElementById('customfield_11106-1').checked){
			AJS.$("#customfield_11118").closest('div.field-group').hide();
			document.getElementById('customfield_11118').value = "";
		}
		if (document.getElementById('customfield_11106-2').checked){
			AJS.$("#customfield_11118").closest('div.field-group').show();
		}
	
		AJS.$('#customfield_11106-1').click(function(){
			if (document.getElementById('customfield_11106-1').checked){
				AJS.$("#customfield_11118").closest('div.field-group').hide();
				document.getElementById('customfield_11118').value = "";
			}
		});
		
		AJS.$('#customfield_11106-2').click(function(){
			if (document.getElementById('customfield_11106-2').checked){
				AJS.$("#customfield_11118").closest('div.field-group').show();
			}
		});
}
AJS.$(document).ready(function(){newField()});
AJS.$(document).bind('dialogContentReady', function(event, dialog){newField()});
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e,context){newField()});
newField();
</script>

And using this script at the announcement banner

<script type="text/javascript">
AJS.$("#create_link").removeClass("create-issue");
</script>

Hi Ana,

I am able to use your example script, but my JIRA hangs up when I create a project/issue type that does not have the two custom fields in the create screen. Can you help? Thanks

This is the script:

<script>

function newField(){

        if (document.getElementById('customfield_10201').value != 35){

            AJS.$("#customfield_11201").closest('div.field-group').hide();

            document.getElementById('customfield_11201').value = "";

        }

        if (document.getElementById('customfield_10201').value == 35){

            AJS.$("#customfield_11201").closest('div.field-group').show();

        }

     

        AJS.$('#customfield_10201').click(function(){

            if (document.getElementById('customfield_10201').value != 35){

                AJS.$("#customfield_11201").closest('div.field-group').hide();

                document.getElementById('customfield_11201').value = "";

            }

        });

         

        AJS.$('#customfield_10201').click(function(){

            if (document.getElementById('customfield_10201').value == 35){

                AJS.$("#customfield_11201").closest('div.field-group').show();

            }

        });

}

AJS.$(document).ready(function(){newField()});

AJS.$(document).bind('dialogContentReady', function(event, dialog){newField()});

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

newField();

</script>

 

Nevermind we Fix it. We added a Null for the value.

 

This widget could not be displayed.
Henning Tietgens Community Champion May 07, 2014

For properly working javascript, you have to provide it as a web ressource plugin. See https://answers.atlassian.com/questions/287928/adding-javascript-to-hide-and-prefil-summary-while-creating-an-issue

Henning

This widget could not be displayed.

Hi Ana,

Maybe this modification fixes your problem:

&lt;script&gt;
(function($) {
    checkbox_11106_1 = document.getElementById('customfield_11106-1'); //New - Yes
    checkbox_11106_2 = document.getElementById('customfield_11106-2'); //New - No
     
    if (!checkbox_11106_1.checked){
        AJS.$("#customfield_11118").closest('div.field-group').show();
    }
    if (!checkbox_11106_2.checked){
        AJS.$("#customfield_11118").closest('div.field-group').hide();
        document.getElementById('customfield_11118').value = '';
    }
     
    checkbox_11106_1.onclick=function(){
        if (checkbox_11106_1.checked){
            AJS.$("#customfield_11118").closest('div.field-group').hide();
            document.getElementById('customfield_11118').value = '';
        }
    };
    checkbox_11106_2.onclick=function(){
        if (checkbox_11106_2.checked){
            AJS.$("#customfield_11118").closest('div.field-group').show();
        }
    };
})(AJS.$);
&lt;/script&gt;

This widget could not be displayed.

Hi,

there is a lot of answer to questions like yours. among it this, you must just replace ids of your custom fields.

https://answers.atlassian.com/questions/264320/pop-up-a-user-picker-window

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted 18 hours ago in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

45 views 1 0
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you