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.
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)
}
}
}
Hi Tuncay, that has nearly worked. The only problem is you need to select two Radio buttons for the corresponding fields to appear??
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.