Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to display/hide a Field based on another Field's selection

Deleted user February 9, 2018

Hi

i would liketo hide some fields (or tab if this is possible) if in another field is something

i found this script : 

<script type="text/javascript">
priority = document.getElementById('priority');
if (priority) {
target = document.getElementById('customfield_10142');
// Hide the target field if priority isn't critical
if (priority.value != 2) target.style.display='none';

priority.onchange=function() {
if (this.value == 2) {
target.style.display = '';
target.value="enter message here";
} else {
target.style.display='none';
}
}
}
</script>

 

And this is working but only in a new window, if i'm creating issue in pop-up window its not working.

 

I'm putting this script in description of custom field.

I would like do this without plugins.

 

Thanks

1 answer

0 votes
Danyal Iqbal
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, 2018

That makes sense. The popup ( js) is only loaded once.

Select the correct project and issue type (with applicable js) in the popup. Close and reopen the popup. The js should work only when customfield_10142  is already present on the form when you open the popup. If you have to change the project/issue-type in the popup, your js has already failed before that.

As a workaround you can execute the js everytime the issue-type /project is changed (exactly like the example script).

Deleted user February 9, 2018

And how i can execute the js everytime ? 

Danyal Iqbal
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, 2018

put the script inside

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

e.g


JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e, context) {
console.log("new content added")

priority = document.getElementById('priority');
if (priority) {
target = document.getElementById('customfield_12400');
// Hide the target field if priority isn't critical
if (priority.value != 10001) target.style.display='none';

priority.onchange=function() {
if (this.value == 10001) {
target.style.display = '';
target.value="enter message here";
} else {
target.style.display='none';
}
}
}
})
Deleted user February 9, 2018

I have to copy all of the code do the description of field ? 

Only change customfield id and priority.value ? 

Danyal Iqbal
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, 2018

yes and don't froget the <script type="text/javascript"></script > tags :)

TG
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 6, 2018

Hello. Does that work on a JIRA server 7.3.3 ? Does it rquires a script-runner plugin or kind-off ? Regards.

Danyal Iqbal
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 6, 2018

It should work on jira server by putting the script in the description of custom field present on that screen.

TG
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 6, 2018

I introduced the code into a field-configuration field description. At issuecreation time, the code is just rendered as plain text. Not interpreted as code. I.E. I can reed the displayed code on the issue pop-up screen. Maybe I must change the main field description as opposed the to field-configuration field description ?
Also, I understood now JIRA would not let JS code inserted in description be ran as code ? So... I am confused.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events