Hide / Show fields based on another fields radio button selection.

Karl Samson
Contributor
February 26, 2025

I'm trying to only show certain text fields dependent upon a certain Radio button selection. There are multiple options available and so only want to show the appropriate corresponding text field, when the radio button is selected.

Currently I have the below server-side script, against the Radio button field in ScriptRunner, but it is only currently looking for one of the multiple options.

 

 

def radioField = getFieldById(getFieldChanged()) // Get the radio button field
def dependentField = getFieldByName("Design Metallics - Hours") // The field to show/hide

if (radioField.getValue() == "Show") {  // Adjust based on your option value
    dependentField.setHidden(false)  // Show the field
} else {
    dependentField.setHidden(true)  // Hide the field.
Snapshot of the fields in question:-
Radio Button options.jpg

1 answer

0 votes
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 26, 2025

Hi @Karl Samson 

Since you have multiple options, you need to update your script to handle multiple selections dynamically. Below is the code that I believe will assist, but please bear in mind that I haven't tested it. I put some comment lines for clarity, I hope it helps

def radioField = getFieldById(getFieldChanged()) // Get the radio button field

// Map each radio button option to its corresponding field
def fieldMappings = [
"Design Metallics" : getFieldByName("Design Metallics - Hours"),
"Design Composites" : getFieldByName("Design Composites - Hours"),
"Design Fluid Systems" : getFieldByName("Design Fluid Systems - Hours"),
"Design Electrics" : getFieldByName("Design Electrics - Hours"),
"Structures Change" : getFieldByName("Structures Change - Hours"),
"Structures Sustainment" : getFieldByName("Structures Sustainment - Hours"),
]

// Get the selected value(s) from the radio button
def selectedValues = radioField.getValue()

// Hide all fields initially (then we will set their hidden property accordingly)
fieldMappings.each { key, field ->
field.setHidden(true)
}

// Show the field if the option is selected
if (selectedValues) {
selectedValues.each { selected ->
def correspondingField = fieldMappings[selected]
if (correspondingField) {
correspondingField.setHidden(false)
}
}
}

 

Karl Samson
Contributor
February 26, 2025

Hi Tuncay, that has nearly worked. The only problem is you need to select two Radio buttons for the corresponding fields to appear??

def radioField = getFieldById(getFieldChanged()) // Get the radio button field

// Map each radio button option to its corresponding field
def fieldMappings = [
  "Design Metallics" : getFieldByName("Design Metallics - Hours"),
  "Design Composites" : getFieldByName("Design Composites - Hours"),
  "Design Fluid Systems" : getFieldByName("Design Fluid Systems - Hours"),
  "Design Electrics" : getFieldByName("Design Electrics - Hours"),
  "Structures Change" : getFieldByName("Structures Change - Hours"),
  "Structures Sustainment" : getFieldByName("Structures Sustainment - Hours"),
   "Engineering Integration" : getFieldByName("Engineering Integration - Hours"),
    "Change Integration" : getFieldByName("Change Integration - Hours"),
     "Project Management" : getFieldByName("Project Management - Hours"),
    "Commercial" : getFieldByName("Commercial - Hours"),
    "Configuration Management" : getFieldByName("Configuration Management - Hours"),
]

// Get the selected value(s) from the radio button
def selectedValues = radioField.getValue()

// Hide all fields initially (then we will set their hidden property accordingly)
fieldMappings.each { key, field ->
  field.setHidden(true)
}

// Show the field if the option is selected
if (selectedValues) {
  selectedValues.each { selected ->
    def correspondingField = fieldMappings[selected]
    if (correspondingField) {
      correspondingField.setHidden(false)
    }
  }
}

Radio Button options_2.jpgRadio Button options_1.jpg

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
9.12.15
TAGS
AUG Leaders

Atlassian Community Events