Hello Friends,
i want to hide/show some custom fields on a form using ScriptRunner Behaviours for a custom field checkbox: "Validation Type".
Unfortunately, it doesn't work as aspekted:
- it shows all custom fiels initial
- it doesn't hide (dynamically) the wished field when uncheck a box
Here is my code:
Where did you set this script ? As initializer or in the server side script on the custom field in the Behaviour config ?
It has to be on the field not the initilizer otherwise it will not run when the field value is updated.
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
One of the reason could be the the selectedOptions line, something weird with the checkbox is that if you select only 1 option, the result is a String not an array.
Could you try this instead to get the selectValues ?
List<String> selectedOptions = checkboxField.getValue() instanceof String ? [checkboxField.getValue()] as List<String>: checkboxField.getValue() as List<String>
Regadrs
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.
Hi Florian,
thank you very much it worked :)
But i have now the following problem:
The Text Fields stay visible when unchecking the represented checkbox.
Here my (new) Code:
import com.onresolve.jira.groovy.user.FormField
def FormField checkboxField = getFieldByName('Naqibullah Test Checkboxes')
List<String> selectedOptions = checkboxField.getValue() instanceof String ? [checkboxField.getValue()] as List<String>: checkboxField.getValue() as List<String>
// My fields to hide/show
def FormField field1 = getFieldByName('Naqibullah Test Textfield 1')
def FormField field2 = getFieldByName('Naqibullah Test Textfield 2')
if (selectedOptions.contains('Test 1')) {
field1.setHidden(false)
} else {
field1.setHidden(true)
}
if (selectedOptions.contains('Test 3')) {
field2.setHidden(false)
} else {
field2.setHidden(true)
}
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.