I'm trying to validate the value of a checkbox using behaviour plugin but the custom field behave oddly. What I'm trying to do is to show/hide other custom fields based on the selection on the checkbox. So for example if I have 3 options in the checkbox, then each option will reveal/hide another custom field as they are ticked/unticked.
I wrote a simple groovy script behind the checkbox that consist of 3 if statements using contain (as explained here) for each option. However the script only seems to work when only 1 option is selected. So when I choose option A the script works fine, but when I choose B afterwards the second if statement doesn't fire. However if I uncheck A and leave B on the script works. It is the same with the other combination.
When I tried to display the value of the selected checkbox using setHelpText, only the first option is shown. Is there something wrong with the logic of my script or is that the expected behaviour of checkbox custom field (i.e. the selected value doesn't stack, only the first one is considered)?
Community moderators have prevented the ability to post new answers.
Hmm that behaviour doesn't apply to me. What I tried to do is display the ticked value of the custom field using behaviour script (setHelpText) and it only display one value at a time. Can you confirm what is showing in yours? Does it mean that when more than 1 option ticked the value will be appended?
I doubt that. If I use a condition like cfValues['my Field']*.value.contains("Value2"), it works also if there are several values beside "Value2" ticked.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's alright Udo, appreciate your effort :) Maybe you can help me with the following: I guess my question is partially about the behaviour of checkbox field. The reason the above code is not working as it should is because the checkbox field only recognize the value when there is only one option is ticked. Is this a bug or the expected behaviour of checkbox custom field?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Since I'm not the scripting expert. I can't help you at the moment. I guess other can do so, especially with this code shared.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Udo, My script is really simple: FormField cfFormA = getFieldById("cfA") FormField cfFormB = getFieldById("cfB") FormField cfFormC = getFieldById("cfC") if (getFieldById(getFieldChanged())*.value.contains("Value A")) { cfFormA.setHidden(false) } if (getFieldById(getFieldChanged())*.value.contains("Value B")) { cfFormB.setHidden(false) } if (getFieldById(getFieldChanged())*.value.contains("Value C")) { cfFormC.setHidden(false) } And set all the fields as hidden before. I assume that the script will be invoked every time there is a change to the checkbox e.g. if there is an additional option selected however it seems to only works when there is only ONE option selected at a time. I'm wondering if this is the default behaviour or perhaps only happened in mine?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It would help if you show your script!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.