Behaviors: how to make checkbox custom field options hide/visible depending on selected checkboxes inside of the field.

Hi, Folks!
You know, I'm trying to make some checkboxes hidden when I select specific checkboxes of the field.
For example, I have:
"Custom Field" - checkbox type
"A","B","C","D" - the values of this field.
IF I select values "A"&"B" so that values "C" & "D" should be hidden.
How can I solve it is?
Please help me.
Many thanks for advice.

2 answers

1 accepted

1 vote
Answer accepted

This isn't really possible through behaviours, its only possible to hide the complete field not specific checkboxes within it. 

Although as a workaround you could use two separate checkboxes and have this script on the checkbox field which contains "A" and "B" and "C" and "D" are on a completely different field. It sounds like they are kind of independent anyway.

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

// this field contains boxes A and B
def checkboxField = getFieldById(getFieldChanged())

// This contains boxes C and D
def otherCheckboxField = getFieldByName("Other Checkbox")

def values = checkboxField.getValue() as List<String>

if (values.containsAll(["A", "B"])) {
    // hide field containing C and D when A and B selected
    otherCheckboxField.setHidden(true)
}

Hi @Adam Markham [Adaptavist], just wanted to clarify:

 

Is it not possible to hide checkbox field options at all, or only in the use case presented in the question?

 

I can use the script below to hide options on a Select field using the Behaviours initializer, but it doesn't work when applied to a checkbox field. I thought they were controlled by same Options classes? Please excuse me if I'm using incorrect nomenclature.

def formField = getFieldByName("Some field");
def customField = customFieldManager.getCustomFieldObject(formField.getFieldId());
def config = customField.getRelevantConfig(getIssueContext());
def options = optionsManager.getOptions(config);

def optionsMap = options.findAll {
    it.value in ["Some option"] 
}.collectEntries {
    [
        (it.optionId.toString()) : it.value
    ]
} 
formField.setFieldOptions(optionsMap);

 

 

  

Do we know if Adaptavist has thise feature in future roadmap to hide options on checkboxes using behaviors ?

try this

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.ComponentManager
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.*
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException

@BaseScript FieldBehaviours fieldBehaviours

def A= getFieldById("customfield_10109")
def B= getFieldById("customfield_10120")
def C= getFieldById("customfield_10018")
def D= getFieldById("customfield_10019")
def E= getFieldById("customfield_10201")
//def F= getFieldById("customfield_10124")
//def G= getFieldById("customfield_10203")
//def H= getFieldById("customfield_10204")
//def I= getFieldById("customfield_10201")
//def F= getFieldById("customfield_10206")
//def J= getFieldById("customfield_10205")


if (A.getValue() == "aaaa"){
B.setHidden(false);
C.setHidden(false);
D.setHidden(false);
E.setHidden(false);
}
if (A.getValue() == null){
A.setHidden(true);
B.setHidden(true);
C.setHidden(true);
D.setHidden(true);
}

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page

                                                      &nbsp...

246 views 0 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