how to hide default watchers field from issue view screen?

Hey all,

 

I am using watcher plugin. So I created new created new field called "watcher"(Watcher type field) through this plugin. It works great providing features like adding watchers anytime and for some automations. 

 

We are planning to use this watcher field for browse permission. In order to avoid any confusion, I want to hide the default watchers field. Is there a way to hide this using velocity templates?

1 answer

1 accepted

1 vote
Accepted answer

I am not sure about editing the velocity template as a means to hide this information in Jira.  That approach might be possible to do as well. 

However I think I might have another way to hide this from view.   My approach was to try to use a custom javascript that would hide those page elements from being displayed when the browser renders the page.

In this case I added this javascript to a custom field description.   In this case, it might be best just to create a new custom field that only appears on the project(s) where you want to hide the watch field in Jira.   This way when Jira loads the page that contains this custom field, looking at this issue details view will still trigger this custom script to run and in turn hide these elements.   Otherwise, adding this to a description of a field that appears on all Jira issues for example, this would cause all these issues to hide these page elements from view.

In my testing I found that I could hide the default Watcher field on issue details view with the script of:

<script type="text/javascript">
    AJS.toInit(function(){
      AJS.$('#watching-toggle').hide();
      AJS.$('#view-watcher-list').hide();
      AJS.$('#peoplemodule > div.mod-content > ul:nth-child(2) > li > dl:nth-child(2) > dt').hide();
    });
</script>

It's possible that your #peoplemodule entry might be different.  I'm afraid that the watcher elements don't exactly have an explicit selector name/id, which makes it a bit more tricky to hide these with a script.  If you're Jira instance has more elements under this People section, say because you might be using another plugin to Jira, then then one of the nth-child attributes might be a different number for your Jira instance.

I have put this in announcement banner and it worked. 

I am assuming this code will just hide the watcher from the user view and the field still exists on the screen. If someone tried to add watcher via rest api it will work?

Could you explain your code?

Yes, that is true.  This just hides this element from being displayed on the web page.  It does not disable any REST functionality with Jira.  So yes, a REST user could still use/see this watcher information.

The code is derived from this Confluence guide on hiding page elements:  How to hide elements in Confluence using CSS or JavaScript.

What I did was to click and select this part of the page itself, then right click and select the Inspect option in my browser.  I know Chrome and Firefox have this option to show you the html code of the page.  From there it is a matter of finding the selector tags in the code in order to hide those elements.

This is great. Thanks for explaining and pointing to the kb article. I have tested this in my sandbox environment. It works both in field and announcement banner. For some reason it doesn't work in custom field in production but works in announcement banner. 

So I am assuming nth child element is correct but it is not rendering through the custom field? 

I got it to work by adding it to description of custom field in field configuration of the specific project. Still would like to have it work globally.

I used a custom field to do this because I knew I could control exactly which screens in Jira this custom field would appear on.  That might be why that doesn't work in your environment.  If the screen you are using in Jira does not yet contain that custom field, then the script does actually get injected into the page display this way.

The announcement banner is another way to do this, but doing that makes sure this happens site wide.  Meaning every page in this Jira instance would have that little javascript running to hide those elements.

It is working ok. But the drawback is after entering the value in the custom field and saving makes the default watchers field visible. 

 

Reloading the page will hide the default watchers again. Is there a way to not show the default watchers after saving the custom watcher field?

 

Also found another interesting thing. If the user doesn't have edit permission, I believe javascript is not executed. Hence both watcher fields are visible!

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 16, 2018 in Jira

Looking for anyone who made the switch to Data Center

The Jira Marketing team is putting together an ebook on migrating to Data Center. We're looking for pro tips on how you staffed your project team and organized your Proof of Concept. Share yo...

1,179 views 16 10
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you