Hello Friends,
This is one of the tutorials under jira development. There may be requirement when you need to use the wiki rendered custom field instead of Free Text rendered field. Also, sometimes you may need such fields to be shown only when certail criteria are matched. So in this case you need to hide those fields by default so that the normal user cannot view or edit the field. This tutorial demonstrates how the field can be hidden from the screen.
Let us consider an example where we have one select list type field, say SelectType with 4 options A, B, C, D. Now we want that whenever the option C is selected we need to display the wiki rendered custom field W , and for remaining options W will be hidden.
So, we need to write the javascript in the description area of customfield W. Following is the code for that.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
; html-script: true ]<script type="text/javascript"> function showhideWikiField() { if (selectList.options[selectList.selectedIndex].text=="C" ) { wikiField.style.display = ''; } else { wikiField.style.display = 'none'; } } /* this is the select list type customfield value */ var selectList = document.getElementById('customfield_11001'); /* this is the wiki rendered type customfield "W"*/ wikiField = document.getElementById('customfield_11219'); if(wikiField.parentElement) { wikiField=wikiField.parentElement.parentElement.parentElement; } else if(wikiField.parentNode) { wikiField=wikiField.parentNode.parentNode.parentNode; } /* hiding the custom field at start up*/ wikiField.style.display = 'none'; selectList.onchange = showhideWikiField; </script> |
Now, as you can see in lines 20 and 24 we have to get the third parent node and element. If you use only one parentNode and one parentElement then it will only hide the text area and not the labels, so to hide the labels you need to get the parent at the top third level.
Hope this will help you 🙂
Regards,
Nikhil Naoghare.