Hi All,
I'm trying to set a date picker custom field to be required if certain value in another custom field (radio buttons) was chosen.
Tried with no success:
def InstallDate = getFieldByName("Installation Date") def InstallStatus = getFieldById(getFieldChanged()) def selectedOption = InstallStatus.getValue() as String def isInstallSelected = selectedOption == "Certain Value" InstallDate.setHidden(! isInstallSelected) InstallDate.setRequired(isInstallSelected)
And:
def installStatusRadioButtons = getFieldByName("Installation Status") def installDatePicker = getFieldByName(getFieldChanged()) def installStatusRadioButtonsValue = installStatusRadioButtons.getValue() if(installStatusRadioButtonsValue == "Certain Value"){ formField.setRequired(true)}
Also I'll be glad for some clarification what should I use:
Fields | |
Initialiser Function |
Or
Add Field | |
Add one or more fields to this Behaviour. |
Maybe configure some general settings in a certain way?
Thank you in advance!
Hi Eitan,
In order to answer your questions above you should use the Add Field option in order to configure the behaviour on a particular custom field. You can find more information on how to configure Behaviours here.
Also I have attached below a sample script along with its config that will allow you to make a custom date picker field required based on the value of a radio button.
This code was developed and tested on JIRA 6.4.12 using ScriptRunner 4.1.3.10.
Code:
// Get pointers to my fields def radiocf = getFieldByName("Installation Status") def datecf = getFieldByName("Installation Date") // Get the radio buttons value String radioCfVal = radiocf.getValue() // If option A is selected in the Installation Status radio buttons // then make Installation Daterequired else make it optional. if(radioCfVal == "A"){ datecf.setRequired(true) }else{ datecf.setRequired(false) }
Config:
image2016-4-4 15:56:55.png
I hope this helps
Kristian
Kristian, thank you for the great answer! Works like a charm.
Just an additional question if you're able to advise-
The date field becomes required only when going to "Edit" option in the issue and prevents from leaving the screen as expected.
However, the condition field ("Installation Status") is editable also in the default screen. There, if I'm picking the "A" option - nothing happens. Apparently because the date field doesn't appear on the default screen until being edited and populated with any value.
Do you have any proposals how can I condition this behavior to happen on the default screen also?
Thank you
Eitan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI Eitan,
Behaviours only happen on the create and edit screen. The fields would need to be available on both screens in order for the behaviour to work.
I hope this helps.
Kristian
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.