Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,361,794
Community Members
 
Community Events
168
Community Groups

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

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

Apps for Confluence you won't want to miss: RSVP for September's Appy Hours

Calling all collaborators and Confluence users! Our Appy Hours event on September 29th features 4 presenters demoing functionality to superpower Confluence. Don't miss learning about these apps i...

125 views 0 9
Read article

Atlassian Community Events