Need to hide a checkbox field

I have a Single Choice select list (Environment) and two check boxes (Norman Privileges and Admin Privileges). Currently I want to show Admin Privileges only if Production from Environment dropdown is selected. Otherwise it should hide that field. I am trying this script and it is not hiding the field. Could you please let me know if I am doing anything wrong here?

 

<script type="text/javascript">

    jQuery(document).ready(function($) {

        JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {

            callChangeFunction();

        });

 

        callChangeFunction();

 

        function callChangeFunction() {

            showHideField();

 

            $("#customfield_12440").change(function() {

                showHideField();

            });

        }

 

        function showHideField() {

            var environment = $.trim($("#customfield_12440 :selected").text());

 

            $("#customfield_16144").parent().hide();

 

            if (environment == 'Production') {

                    $("#customfield_16144").parent().show();

            }

 

            if (environment == 'Non-Production') {

                $("#customfield_16144").parent().hide();

            }

        }

    });

</script>

4 answers

0 votes

There's a really easy answer to "what is being done wrong" - it's "using javascript in JIRA"

Technically, I don't think there is anything really wrong with your code, other than the .parent calls  might not be quite right, and I'm not sure what version of jquery/JIRA you're aiming for.

Nic:

Thank you for replying. I got this script to work and it is working fine right now. The field gets hidden upon selecting a value in the dropdown. I had one change to make and removed the javascript. I thought the field will not get hidden and it is still hiding the field even after removing the script. I removed the internet cache, restarted JIRA and still the same. Is there any issue?

Udaya

0 votes

I don't think so, your browser probably cached some javascript that has now been cleared out.  You've not described what is not working.

NIC:

whenever I was selecting Non-Production, Admin Privileges field was hiding. When I removed the JavaScript on the Admin Privileges field, cleared the browser cache and restarted JIRA, the field is still hiding when Non-Production field is being selected. This is what was happening.

 

Udaya

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Tuesday in Bitbucket

Upgrade Best Practices

Hello! My name is Mark Askew and I am a Premier Support Engineer for products Bitbucket Server/Data Center, Fisheye & Crucible. Today, I want to bring the discussion that Jennifer, Matt, and ...

158 views 3 6
Read article

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