I'm in the process of using the Behaviours plugin to create a custom form based on choices made the user. For example if they select one particular option (or that option and others) two text fields will appear for user entry.
I'm not sure if I am attempting to do this correctly or not, but I've spent ages trying to find a solution with zero luck.
I intend to use a switch statement to check each ID in the custom field. However, for the life of me I can't get a list to work which will store the IDs of the multi checkbox field to use as the cases for the switch. (NB: I haven't finished writing all the cases for the switch, and won't until I have the few cases there actually working).
I've gone through so many different variations that haven't work, I didn't save them all, so I have no code for reference in regards to list creation. All I have is below, the gap being for where the list should be declared (or something similar which will work).
FormField fAccess = getFieldByName("Access Details") FormField fDrive = getFieldByName("Drive mappings required") FormField fEmail = getFieldByName("Email groups required") switch (values) { case ['11205']: fDrive.setHidden(false) fEmail.setHidden(false) break case ['11203', '11204', '11205', '11206', '11207', '11208']: fDrive.setHidden(false) fEmail.setHidden(false) break case ['11203', '11204', '11205', '11206', '11207']: fDrive.setHidden(false) fEmail.setHidden(false) break case ['11203', '11204', '11205', '11206']: fDrive.setHidden(false) fEmail.setHidden(false) break case ['11203', '11204', '11205']: fDrive.setHidden(false) fEmail.setHidden(false) break case ['11203', '11205']: fDrive.setHidden(false) fEmail.setHidden(false) break case ['11204', '11205', '11206', '11207', '11208']: fDrive.setHidden(false) fEmail.setHidden(false) break case ['11205', '11206', '11207', '11208']: fDrive.setHidden(false) fEmail.setHidden(false) break default: fDrive.setHidden(true) fEmail.setHidden(true) break }
FormField fAccess = getFieldByName("Access Details") FormField fDrive = getFieldByName("Drive mappings required") FormField fEmail = getFieldByName("Email groups required") FormField fInf = getFieldByName("Information") FormField fAlloc = getFieldByName("Allocation") String Acc = (String) fAccess.getFormValue() List<String> AccList = Acc.replaceAll(" ", "").minus("[").minus("]").split(",") boolean networkAccessChecked = false boolean corporateSiteChecked = false for ( String i in AccList ) { if (i == "11205") { networkAccessChecked = true } if (i == "11207") { corporateSiteChecked = true } } if (networkAccessChecked) { fDrive.setHidden(false) fEmail.setHidden(false) } else { fDrive.setHidden(true) fEmail.setHidden(true) } if (corporateSiteChecked) { fInf.setHidden(false) fAlloc.setHidden(false) } else { fInf.setHidden(true) fAlloc.setHidden(true) }
Nevermind, I finally got it to work and instead went for the much neater for loop over a switch.
Code above for any interested.
HI, can you please share the updated script for multi check box field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.