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

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

Inayat Nahvi April 8, 2021

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

Comment

Log in or Sign up to comment
Ravi Sagar _Sparxsys_
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.
April 8, 2021

Hi @Inayat Nahvi 

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

Peter-Dave Sheehan
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.
April 8, 2021

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 Nahvi likes this
Inayat Nahvi April 12, 2021

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

TAGS
AUG Leaders

Atlassian Community Events