Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Is it possible to hide check boxes based on selection within the check box field?

Hi,

Here is my scenario:

1). Let's say I have a custom checkbox field with options 1,2,3,4,5,6,7,8,9,10.
2). Initially, I only want options 1,2,3,4,5 visible to the user, and 6-10 hidden. Options 1-5 should always be visible.
3). If the user checks option1, then make 6,7,8 also visible. If the user checks options2, make 9,10 visible.
4). If the user unchecks 1, then 6,7,8 are hidden again. If the user unchecks 2, then 9,10 are hidden again.

Is this possible do to within a single custom field? Is there a behavior for this?  I have not seem an example of this so far.  Has anyone else?

 

2 comments

Ravi Sagar Community Leader Apr 08, 2021

Hi @Inayat N 

I think it can be done. I haven't played with checkboxes using behaviours recently but if you look at this page you can use the script and try it yourself.

Ravi

Here is how I would implement this using behaviours.

You will need to create a server-side initializer script, and a server-side script for your checkbox field.

Place this code in both script boxes (adjust for field name and actual option values):

import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.customFieldManager
def optionsManager = ComponentAccessor.optionsManager

def chkField = getFieldByName('checkbox1')
def initalOptions = ['1','2','3','4','5']
def conditionalOptionMap = [
'1':['6','7','8'],
'2':['9','10']
]

def chkCf = customFieldManager.getCustomFieldObject(chkField.fieldId)
def chkConfig = chkCf.getRelevantConfig(issueContext)
def chkOptions = optionsManager.getOptions(chkConfig)

def selectedOptions = chkField.value
//turn single value string into an array of 1
if(selectedOptions instanceof String) selectedOptions = [selectedOptions]
def showOptions = chkOptions.findAll{opt->
opt.value in initalOptions ||
selectedOptions.any{
opt.value in conditionalOptionMap[it]
}
}
chkField.setFieldOptions(showOptions)

The initialiser will run when you first open the create (or edit) screen. The field script will run every time you check/uncheck any of box.

Like Inayat N likes this

Thanks @Peter-Dave Sheehan .   This is perfect.  It works just as I needed.

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

463 views 5 18
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you