How to hide the Wiki Rendered custom field using java script?

Nikhil Naoghare July 11, 2011

Hi Team,

I need to hide the custom field which is Wiki Rendered. Actually, i need this wiki rendered custom field to be shown on the screen only when one of the option is seleced form the cascaded field. This runs right when i use the same code for same field when i change its rendering to Free Text Type. Can you please tell me if any specific changes needs to be made for this.

3 answers

0 votes
Nikhil Naoghare July 13, 2011

Check this out for this:-

Hiding the wiki custom field

0 votes
Nikhil Naoghare July 12, 2011

HI Matthew,

Thanks for your answer. I have one query -

flagFieldValue = document.getElementById(cfTriggerName + "-val"); /* -val elemement is a Jira 4.2+ view screen */

here what -val represents is that any value or Screen ID???

Please suggest.

Thanks,

Nikhil.

MatthewC
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.
July 12, 2011

Sorry one last comment ;-) Here is an example of the view screen HTML for a CF

<li id="rowForcustomfield_10543" class="item"><div class="wrap"><strong title="QcReqId" class="name">QcReqId:</strong><div id="customfield_10543-val" class="value type-textfield">1587</div></div></li>

MatthewC
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.
July 12, 2011

It's a literal string...Look at the source of the view screen you'll see that the actual DIV with the value is called "customfield_10543-val". You get this & then inspect it's contents to see the value of the custom field (on the view screen).

MatthewC
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.
July 12, 2011

If your target field is blank then it won't show on the screen anyway & you won't need this extra code to hide it. It's only if there is data in this field but you still want to hide it. Not always a good idea as it will still show up in other views (search, xml, csv)

MatthewC
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.
July 12, 2011

But then there is the question of what happens if userselects the trigger value, target CF field appears, enter data, saves. Then goes back in selects another (non-trigger) value, target CF field disappears but the data is still there & they save. Do you want the data in the target field to also be blanked? Hard to say without knowing exactly what you are doing.

0 votes
MatthewC
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.
July 11, 2011

*UPDATE*

Having trouble adding comments so I've updated the answer....

If the labels are still appearing, it's because we need to get rid of the whole line. In pre-Jira 4.2 everything was wrapped in a Field Area so we could do a document.getElementById('customfield_10543FieldArea'); and hide the lot.

However, since 4.2 we have to find the custom field and reference the parent node in the DOM.

I'll post a complete example for the create screen

*UPDATE*

Here is a bit of code that I've used for something similar, it may be of some use. It's written from memory so please forgive any typos!

<script type="text/javascript">

/* ASUMPTIONS: two custom fields.... */

var cfToHideName = "customfield_10543";

var cfToHideViewName = "rowForcustomfield_10543"

var cfTriggerName = "customfield_10544";

var hideTriggerValue = "SOME_VALUE";

/* Javascript for hiding the field on a view screen */

var targetCFViewRow = document.getElementById(cfToHideViewName);

If (targetCFViewRow != null) {

/* get the containing DIV for the custom field */

var targetFieldWrapper = targetCFViewRow.parentNode;

if (targetFieldWrapper != null) {

/* We have the containing DIV for the field we wish to hide, now get the other field & check it's state */

/* This is only for the veiw screen but since we don't know where this JS will be rendered, it will have to do some checks */

flagFieldValue = document.getElementById(cfTriggerName + "-val"); /* -val elemement is a Jira 4.2+ view screen */

/* if the flag field value is set, expose the target field

if (flagFieldValue != null && flagFieldValue.innerHTML.equals(hideTriggerValue) {

/* Show the target field row */

targetFieldWrapper.style.display='';

} else {

/* else hide the field row */

targetFieldWrapper.style.display='none';

}

}

} /*end if targetCFViewRow (VIEW screen) */

/* Now the code for the EDIT /CREATE screen */

/* setup the event handler for the other custom field so that if the user changes it, we can switch visibility on & off */

var flagFieldCF = document.getElementById(cfTriggerName);

if (flagFieldCF != null) {

var editTarget = document.getElementById(cfToHideName).parentNode;

/* Hide the target field if the value is set */

if (flagFieldCF.value==hideTriggerValue) editTarget.style.display='none';

/* set the onchange event handler */

flagFieldCF.onchange=function() {

if (this.value == hideTriggerValue) {

editTarget.style.display='';

} else {

editTarget.style.display='none';

}

} /* end onchange() */

}

/* end of EDIT/CREATE screen JS code */

</script>

Nikhil Naoghare July 11, 2011

Hi Mathew, I am trying to hide the field on the create screen itself.

Also, i would like to mention one this The script works fine when i change the rendering from Wiki to Free text. Its just that the labels are still on the screen though the text or field area is not visible.


MatthewC
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.
July 11, 2011

Hi Nikhil, I've updated my answer assuming that you jave Jira 4.2+ and that you are looking to hide a field on both the view & edit screens. You only need the 2nd bit if it's just the edit/create screen. Hopefully my assumptions are right but let me know if itts not

Suggest an answer

Log in or Sign up to answer