Documentation for JIRA 6.4 EAP. Not using this? See below:
(JIRA 6.3.x documentation | JIRA Cloud documentation | earlier versions of JIRA)

Skip to end of metadata
Go to start of metadata

This page has permanently moved to JIRA Knowledge Base at How to display a Field based on another Field's selection.

49 Comments

  1. I’m not sure what does the 3rd step “change the custom field id and priority id” mean,is anyone explaining the details?

    1. The target custom field id (customfield_10420FieldArea in this case) should be changed to the field that will be affected.
      The source field id (priority) should be changed to the field that will be affecting the target.
      The id can be found from the the Custom Fields page in JIRA by hovering the mouse over the operation links (such as Edit) for the custom field in question, and taking a note of it from the browsers status bar.
      Depending on the field type and behaviour the logic will be different. In this example if a priority of 2 is selected (which is Critical), the text field will be shown.

      1. Thanks for reply,Rahmani.

        As I was not familiar with the custom field configuration, it cost me several hours to make it.

        Finally,I found there were two operations with the same name for a custom field in different pages,one was 'Edit' in the Custom Fields page,and the other was another 'Edit' in the Field Configurations page.But which did take effect is  the description linked by the 'Edit' in the Field Configurations page, no matter what description was added in the other page.

        This really wore me out.

  2. I have been trying to get hide one custom field based on the value of another custom field (radio buttons). Is there anything in the javascript I need to modify considering I am using a custom field?

  3. This scheme no longer works in JIRA 4.2 since custom fields in the HTML are no longer wrapped by "customfield_xxxxxFieldArea" divs.

    E.g. in JIRA 4.2...

    Solution: for JIRA 4.2, you need to do this instead in the Atlassian-provided example...

    pre-JIRA 4.2: target = document.getElementById('customfield_10420FieldArea');
    JIRA 4.2: target = document.getElementById('customfield_10420').parentNode;

    Everything else in the above example should then work.

    1. Thank You!  I've been searching for the new way to hide afield, since the FieldArea was gone.  Much appreciated for posting this solution.

  4. Possible dumb question... Can I make the "hidden" field required when it displays?

  5. I would also like to know whether a required property can be set using this method.

  6. Good morning:

    I´m trying to make a field visible only if other combo field have the value "Otros".

    I´m using this javascript code in the description field of the combo custom field, but it doesnt work me.

    Is there something wrong?  I´m using JIRA 4.2.

    <script type="text/javascript">

    field = document.getElementById('customfield_10062').parentNode;

    if (field) {

    target = document.getElementById('customfield_10280').parentNode;

    // Hide the target field if field isn't "Otros"

    if (field.value != 'Otros') target.style.display='none';

    field.onchange=function() {

    if (this.value == 'Otros')

    Unknown macro: { target.style.display = ''; }

    else

    Unknown macro: { target.style.display='none'; }

    }

    }

    </script>

    Thanks

    Oscar

    1. Anonymous

      Hi Oscar -- I think your problem is that you don't want to use .parentNode for your source field, only for the target. 

      .parentNode takes you one level up the HTML tree to the <div class="field-group"> tag, which is what you want to set to hidden in the case of the target. 

      For the source, you need the control itself to identify its value, so just use

          field = document.getElementById('customfield_10062')

      Hope that helps.

      1. Good afternoon:

        Thanks for your help.   I have change the code but it still doesn't work.  Is there any wrong?  I´m using Internet Explorer 8.   Is it necessary to restart Jira after any javascript change?

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

        field.onchange=function()
        {
         if (this.value == 'Otros')
         

        Unknown macro: { target.style.display = ''; }

         else
         

        Unknown macro: {  target.style.display='none'; }

        }
        }
        </script>

        Thanks

        Oscar

        1. If you view source on the page in your browser and you don't see the updated javascript coming through, you should check the field description that's part of the field configuration.   That description overrides whatever is in the description field on the custom field itself.   You shouldn't need to restart Jira or even reindex to see the change.

          1. Good afternoon Dave:

            I can see the code but nothing happens.

            I have tried with that simple code and doesnt work.

            <script type="text/javascript">
             target = document.getElementById('customfield_10280');
             target.style.display='none';
            </script>

            what's the problem?

            Thanks

            Oscar

            1. I think that should work, assuming that you're making the calls at the correct time.   Here's an abbreviated version of what we're using:

              <script type="text/javascript">
              // Get screen elements
              source = document.getElementById('customfield_10612');
              target = document.getElementById('customfield_10614').parentNode;
              
              //onload scripts
              window.onload = function(){
              validatedisplay();
              }
              
              //onchange scripts
              if(source != null){
              source.onchange=function() {
              validatedisplay();
              }
              }
              
              //function to vaidate the display
              function validatedisplay(){
              target.style.display = 'none';
              
              // Enable field if necessary
              if(<somecondition>){
              target.style.display = '';
              }
              }
              </script>
              
              

              Strictly speaking, I think we should be looking for the dialogContentReady event rather than using window.onload, but it seems to be working okay for us. See the 4.2 Release Notes for more information.

              1. Oscar - I'm the one who posted as "anonymous" above (forgot to login).  You need to use .parentNode for your target field but not your source.

                You want:

                field = document.getElementById('customfield_10062');
                target = document.getElementById('customfield_10280').parentNode;

                Also, make sure your custom field with the javascript in the description is at the very bottom of your form -- it has to come after any of the custom fields that it references, otherwise they will not exist yet when the script runs.

                See if those two things help.

                1. Good morning:

                  Now it works :)  The question was the position of the customfield. 

                  In my case.  I have a combo and a text field.   When the combo have a value 'Otros', the text field are visible.

                  If I put the text field after the combo the javascript doesnt work. 

                  This is the code:

                  <script type="text/javascript">
                  var field = document.getElementById("customfield_10062");
                  if (field)
                  {
                   var target = document.getElementById("customfield_10280");
                   target.style.display='none';

                   // Hide the target field if field isn't "Otros"
                   if (field.value != 'Otros')
                    target.style.display='none';
                   else
                    target.style.display = '';

                   field.onchange=function()
                   {
                    if (this.value == 'Otros')
                    

                  Unknown macro: {   target.style.display = '';  }

                    else
                    

                  Unknown macro: {   target.style.display='none';  }

                   }
                  }
                  </script> 

                  Regards and thanks!!

                  Oscar

  7. Anonymous

    Hi guys ,

    I am using java script in one of the custom field description area  in jira 4.3.3, but it is not working and same is working in 3.12 version.

    here is my javascript snippet.

    <script type="text/javascript">
    function toggleXXXXSelect() {
        if (checkbox.checked)

    Unknown macro:

    Unknown macro: {      toggleXXXXSelect.style.display = '';    }

    else

    Unknown macro:

    Unknown macro: {      toggleXXXXSelect.style.display='none';    }

    };
      checkbox = document.getElementById('customfield_10111_1');
      toggleXXXXSelect = document.getElementById('customfield_10400FieldArea');

      // Hide the target field by default
      toggleXXXXSelect.style.display = 'none';

      checkbox.onclick=toggleXXXXSelect;
      toggleXXXXSelect();
    </script>

    is javascript works in 4.3.3 or not?

    please help that is there any problem with my javascript.

    1. Anonymous

      Hello,

      I having troubles with 4.3. too! Hopefully, Java Scripting works with 4.3.x.

      Bellow is my script. I am trying to get Jira do a simple calculation:<script type = "text/javascript">
       
       
      var risk = 0;
      var no1= document.getElementById('customfield_12000');
      var no2 = document.getElementById('customfield_12001');
       
       
      no1.onchange= function() {
       
      risk = (no1 + no2);
      document.getElementById('customfield_11604').parentNode = risk;
      };
       
       
      no2.onchange= function() {
       
      risk = (no1 + no2);
      document.getElementById('customfield_11604').parentNode = risk;
      };
       
      </script>
      Please, advise!

      Thanks,

      Velina

  8. Good morning:

    You must to put the script in the Field Configuration screen and not in the Custom fields screen.

    And Its very important the order of the fields in the screen.  The javascript must be in the bottom.

    All the custom fields referenced in the script must be before the custom field u have inserted the script.

    regards

    Oscar

    1. Hello Oscar,

      Your advice and Number() did the magic:) Thanks a lot:)

      1. You´re welcome ;)

        1. Anonymous

          Hi Oscar,

          We are facing critical issue in JIRA 5.The java scripts are not loading properly.The scripting are not getting loaded while creating an issue.If I try creation 2 or 3 times,the java script getting loaded.

           

          Any Idea??

           

  9. Hi All

    I am in JIRA 4.4. Which has been upgraded from 4.1.1.

    I face the same problem.

    Here's my code ;

     

    <script type="text/javascript">

      priority = document.getElementById('priority');

      if (priority) {

          target = document.getElementById('customfield_10061').parentNode;

          // Hide the target field if priority isn't a Blocker

          if (priority.value != 1) target.style.display='none';

           priority.onchange=function() {

              if (this.value == ) {          

                                 target.style.display = '';      

                      } else {

                                 target.value='n/a';

                     target.style.display='none';

              }

          }

      }

     </script>

     

    Any help ?

     

    Thanks

    Vishnu.

  10. Hello everybody,

    I work with JIRA 4.4.4, but I'm not able to make work the field dependent visibility.

    I have carefully read all this "thread", with all its comments, but nothing works for me.

    I have created a new custom field which I place at the end of my screen (so that the referenced custom fields are already loaded). I have tried with and without the "parentNode" and... nothing. What I can say is that I see the script in the source code of the page, but it seems it's not being executed... any idea?

    My code:

    <script type="text/javascript">
      realizadoPor = document.getElementById('customfield_10142');
      if (realizadoPor) {
          target = document.getElementById('customfield_10340').parentNode;
          // Ocultar el campo "Proveedor SAP-FI" si el caso es realizado por Metro
          if (realizadoPor.value == 'Metro')
               target.style.display='none';
          realizadoPor.onchange=function() {
              if (this.value == 'Metro') {             
                         target.style.display = '';
              } else {
                     target.style.display='none';
              }
          }
      }
     </script>

    Anyone knows any other way of achieving the same? (besides the commercial plugin).

    Thank you very much in advance to anyone who dedicated 5 minutes to read this (wink)

    i.

     

    1. I answer myself (smile)

      The problem was the value "Metro": looking at the HTML sent by JIRA to my browser, I saw it had a different value, a numeric one. As soon as I changed the script with that numeric value, everything worked fine.

      I have to say that debugging JavaScript with Firebug (for the first time in my life) was the key.

      i.

       

  11. Anonymous

    Does this no longer apply to the latest version of JIRA OnDemand?  I thought I saw somewhere that HTML was no longer allowed in description fields, using Wiki markup instead.  Does this mean we can no longer use Javascript?  If not, what would be a way to default a date field to two days before another date field (if it's empty)?

  12. Hello,

    if I add any javascript to field description in Field Configuration screen , it doesn´t appear later on editing issue screen.

     I can add any other tags, and tahen it appears on the right place in description (tested with  firebug):, but all content inside of script tag dissapears.

    I have tried with Chrome and Firefox, execution of javascript is enable.

     

    Any suggestions?

    Thank you!



  13. Please update this page, it is not working with JIRA 5 anymore

  14. Anonymous

    Hello,

    I am running JIRA 4.4 and am trying to hide a custom Select type field based on the value of a custom Single Version Picker field.

    I have entered the following script into the Descsription of the Select type field, but am having no luck in making it disappear.

    <script type="text/javascript">
      delivery = document.getElementById('customfield_10747').parentNode;
      if (delivery) {
         version = document.getElementById('customfield_10745').parentNode;
          // Show the Version Number field only if Delivery Required For is Elephant      
      if (delivery.value != 'Elephant') version.style.display='none';
          delivery.onchange=function() {
              if (this.value == 'Elephant') {             
                         version.style.display = ''; 
                      } else {
                     version.style.display='none';
              }
          }
      }
     </script>

     

    Any thoughts on what I am doing wrong, please?

    1. Anonymous

      Hi,

      Sorted my problems - they were that the control field should not have had '.parentNode' after it (in delivery = document.getElementById('customfield_10747').parentNode), and I needed the javascript in the description of the last field on the edit page, not in the description of the last field in the custom list (ordered alphabetically, not by field ID (wink)). After that it all works.

       

      However, if you edit the form, display the field and set it to a value, then change the control value so that the field is not displayed, when you exit edit, the hidden field is still shown on the view screen. Presume this is because it has a value. So, you need to do the following to clear this value and stop its display, where ControlField is the one controlling the display, HideField is the one that is shown or not, ValueM is the value set in ControlField to show HideField:

      <script type="text/javascript">
        ControlField = document.getElementById('customfield_nnnnn');
        if (ControlField) {
           HideField = document.getElementById('customfield_ppppp').parentNode;
           HideFieldBase = document.getElementById('customfield_ppppp');
            // Show the HideField field only if ControlField is ValueM
            if (ControlField.value!=ValueM) HideField.style.display='none';
       
            ControlField.onchange = function() {
                if (this.value == ValueM) {             
                           HideField.style.display = ''; 
                        } else {
                       HideField.style.display = 'none';
                       HideFieldBase.value = -1;
                }
            }
        }
       </script>
  15. Anonymous

    Hi Oscar and other teammates,

    I am using JIRA 4.4 I have issue with customefield hidding. I used same code but the field is only hiding when we click edit issue. Please help me. My code


    <script type="text/javascript">
    // Get screen elements
    source = document.getElementById('customfield_10331');
    target = document.getElementById('customfield_10332');
    target2 = document.getElementById('customfield_10332').parentNode;

    //onload scripts
    window.onload = function(){
    validatedisplay();
    }

    window.onload = function(){
    validatedisplay();
    }
    //onchange scripts

    source.onchange=function() {
    validatedisplay();
    }


    //function to vaidate the display
    function validatedisplay(){
    target.value=source.value
    if (source.value != 10929) target2.style.display = 'none';

    //{
    //target2.style.display = 'none';
    //}
    //ELSE{

    //target2.style.display = '';
    //}


    }
    </script>

  16. Hi there,

    I try on Chrome and JIRA 5.1.3 and put the script under description box in Field configuration, it 's work

    <script type="text/javascript">
    ControlField = document.getElementById('customfield_12500');
    if (ControlField) {
    HideField = document.getElementById('customfield_12501').parentNode;
    if (ControlField.value!='11901') HideField.style.display='none'; //11901 a value represent 'Yes' option in selection list
    ControlField.onclick = function() {
    if (this.value == '11901') {
    HideField.style.display = '';
    } else {
    HideField.style.display = 'none';
    }
    }
    }
    </script>

     

    Thanks,

    Jutamat.

  17. I have a question.

    How to hide the field label name.

  18. HI

    I want to validate  a user field based on radio buttion selection, can we do that with java script as above?

    for e.g

    i have a radion button CR = yes or no,

    if Yes, CR user field is required, check user is added to CR user field, if not show error msg

    If No, CR user field should be empty or clear it if something is there.

    this should  happen in workflow step, i checked in workflow validations, there are no such condition.

    i am thinking we can do by  a simple script or thro java script.

    pls share if anybody has idea on this.

    Thanks

  19. @Wu Yanfeng: If you would link to hide labels from the screen, you can hide it by removing it from the target screen which associated to that project or if you need to hide for all screen you can hide from field configuration.

  20. Anonymous

    Hi everyone,

    I want to hide a field if a special Usergroup is watching the issue, is that also possible?

    Thanks for answers

  21. You should add to the documentation that since JIRA 6 it isn't possible anymore to add HTML to descriptions for third party custom fields. It's only possible for system fields and the standard custom fields. (see  JRA-28776 - Allow HTML to the custom field's Description or the Introduction message (to display on the dashboard) Closed )

  22. Hi,

    Can somone show me a barebones sample for a simple scenario?

     

    disable a radio button field in tab1 based on a field in tab2.

    And also, the fields/tabs stays hidden when they have no value. Are they still accessible via javascript?

    Thanks!

  23. I am trying to show Custom Text Field when Selected option is Other ..I checked also numerical value for them.. But can not able to execute it (sad) Any Help apperciiated

    <script type="text/javascript">

      priority = document.getElementById('customfield_11101FieldArea');

      if (priority) {     

     target =  document.getElementById('customfield_11102').parentNode;

          // Hide the target text field if selected value isn't Other

          if (priority.value != 10702) target.style.display='none';

            priority.onchange=function() {

              if (this.value == 10702) {             

                         target.style.display = '';

                         target.value="enter message here";

                      }  else

    {                 target.style.display='none';

              }

          }

      }

     </script>

  24. I'm storing another jira issue URL information in some customfield. I wanted to hide complete URL and display as issue.

    Suppose, Instead of http://localhost:8080/browse/PROJ-1876it should display as PROJ-1876.

    Using Javascript I can achieve it, But User should have edit permission and field should be in edit screen. So Is there any other way to do this without giving edit permission to users?

    Help me..,

     

  25. Hi,

    I am using JIRA 6.2 and this javascript works on first load of the screen. But if user change project type / Issue type that forces to reload that form using Ajax, then this javascript is not rendered in description field. Is it some bug or this is behaviour? 

    Edit - I found a QA on this, though I have not tested it.

    So I have to user JIRA Behaviour plugin to hide the field based on other custom field.

    Thanks

  26. We have a custom field associated with a workflow to suspend an issue.  When the issue is suspended, it saves a timestamp to the "Suspended Date" date custom field.  Now folks are wanting a field that represents the total amount of time an issue has been suspended.  This is with 6.1.  Any suggestions?  

    Oh, and since dynamic, it would make sense that this would be updated when the issue is viewed on the details screen, or in the issue search screen.

  27. Hi

    I am using JIRA 6.2.1 and i tried the javascript code for changing a  custom filed based a drop selected.

     

    <script type="text/javascript">
    env = document.getElementById('10100');
    if (env) {
    target = document.getElementById('10008');
    // Hide the target field if env is DEV
    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>

     

    I included this code the description of custom filed  and in the field configuration screen. Also the custom filed is placed at the bottom most of the form. It is not working. Please let me know if i am missing anything.

     

    Thanks.

     

     

     

    1. Hi Lak

      In this code, there are 2 problems. 

      1. In getElementByID you should use 'customfield_10100' so the id of CF should be prefixed with customfield_ 
      2. Here the variable priority is not set. So it may not work as desired.

      Also This Javascript functionality is working only when the form loaded initially, if it loaded with Ajax then this javascript does ot loaded.

       

      1. Hi Naren

        I revisited my code and the first point you mentioned made the code to work. It is confusing though because when I see the custom filed id in the URL it is without the prefix "customfield_" and when i do a view source it is shown as 'customfield_10100'.

         

        Thanks

        Lak

  28. Hi Naren

    I revisited my code and the first point you mentioned made the code to work. It is confusing though because when I see the custom filed id in the URL it is without the prefix "customfield_" and when i do a view source it is shown as 'customfield_10100'.

     

    Thanks

    Lak

  29. Wow! What a pain trying to get this to work programmatically. 

    This plugin does exactly what's desired with a couple of clicks in an admin UI. I'm at a loss for both how this has not been mentioned and how I did not find it searching (someone told me about it verbally). 

    https://marketplace.atlassian.com/plugins/com.intenso.jira.plugin.dynamic-forms

  30. Hi guys,

    Can anyone help me with this script? Is it possible to use it to control a total of 3 custom fields (cascade select list)?

    My scenario is the following:

    Customfield1 is displayed by default

    Customfield2 is only displayed if Customfield1 is filled in

    Customfield3 is only displayed if both Customfield1 and Customfield2 are filled in

     

    Thank you for your help.

    Eduardo