Forums

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

Custom fields visibility depending on other selection-field?

Markus Lepper
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, 2011

Hi Jira-experts,

I have a request to generate a new issue type where the issue screen shows different set of custom fields after selecting an option via a drop-dow-selection-box.

In other words:

- Type-selection-box with n entries.

- Depending on the selection an option (1...n) a different set of custom fields shall be shown.

I would not like to have n separate issue types as some fields are common an only some custom fields depend on the selection.

What would be the (easiest) way to implement this feature?

Thanks for any link, suggestion, idea,..!

BR, Markus

3 answers

0 votes
JamieA
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 12, 2011

The value won't be "New Account", because since 4.3 select lists are keyed on an ID. ReqType.value will give you the ID... You need to look at the value.

It's easier if you use jquery: AJS.$("#customfield_10032 :selected").text()

Having said that, stuff like this is why I wrote the behaviours plugin... very similar example here.


Markus Lepper
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 12, 2011

Thanks Jamie,

will look gain into behaviours plugin.

Seems that I'm stcuk even with basics to get ANY javascript running. Curently not even a "alert('True');" generates any reaction.

Could I have disabled AJS? Where? What is the most simple "Hello World"?

1st I need to get scripting running, then I'll check the functionality.

BR, Markus

JamieA
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 12, 2011

An alert has to work - where are you putting it, in the field description? Can you check the page source to make sure that JS is actually making it to the page?

Markus Lepper
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 13, 2011

Hello Jamie,

I've added a most simple javascript into the 'Description of a custom field in a 'Field Configuration' which is linked to a 'Field Configuration Scheme' which itself is attached to the project where I want to get the javascript running.

This is my great script:

<script type="text/javascript">
alert(True);
</script>

I see this code in my browser:

<div class="field-group" >
                                                                        <label for="customfield_10571">Account Type</label>
                <select class="select" name="customfield_10571" id="customfield_10571">
            <option value="-1">None</option>
                <option value="A">A</option>

            <option value="B">B</option>
    </select>
                                       <div class="description"><script type="text/javascript">
alert(True);
</script></div>
                </div>

==> Code is in the webpage, but no alert popping up..

I'm really confused as I know some javascript worked half a year ago.

Any other idea?

BR, Markus

JamieA
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 13, 2011

Hrm, in the example before you had quotes around the True. Try getting chrome, press F12, and paste that in. I get:

> alert(True);
> ReferenceError

There's no such variable as True.

> Code is in the webpage, but no alert popping up..

Make sure the browser is not suppressing javascript error messages...

0 votes
J Thomas
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 6, 2011

See this question about using javascript in screens to get the selected value, and this one about showing/hiding fields.

So get the selected value then show/hide the relevant fields.

Markus Lepper
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 12, 2011

Sorry for late rection...been busy with other stuff.

I've checked the links and found quite some posts in old forum...but still could not get it running.

Added the javascript to the 'Description' box of the field in "Field Configuration" list. Right? or in Description of "Customu fields" list.

<script type="text/javascript">
var ReqType = document.getElementById('customfield_10570');

ReqType.onchange = function()
{
       var field1 = AJS.$("customfield_10571").closest('div.field-group');
	if( ReqType.value == 'New Account' ) {
             AJS.$("#customfield_10571").closest('div.field-group').show(); 
	} else { 
             AJS.$("#customfield_10571").closest('div.field-group').hide();
        }
</script>

* Fields 10570 and 10571 are "Select List" fields.

* 10571 has 2 options: "New Account" and "IT Change"

* Intended reaction:

** 10571 = "New Account" => Show 10571

** 10571 = "IT Change" => Hide 10571

* ..but nothing changes on any selection.

Likely it's this type of tiny bug..could anybody guess where it is?

THANKS, Markus

0 votes
Markus Lepper
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 6, 2011

Nowbody any idea? Help...please ;-)

BR, Markus

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events