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

Serj Shcherbakov August 3, 2016

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
adammarkham
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.
August 4, 2016

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)
}
Damian Rosochacki February 17, 2017

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);

 

 

  

Chander Inguva
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.
May 30, 2017

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

0 votes
Rodrigo Nunes October 23, 2018

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
TAGS
AUG Leaders

Atlassian Community Events