Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Behaviours: How to make custom field required when I select a specific radio button option?

Version - Behaviours with Jira v8.5.1 

I have been using a Beavhiours script for several months now with great success. It currently shows/hides various fields based on user selections (lists, cascading lists, checkboxes). I want to condition the required/optional condition of a text field based on the value of a radio button.

IS: Text field required status not changing when I make correct radio button selection
SHOULD BE: Text field should become required when I select specific radio button

Goal: Use Adaptavist Behaviours to make textField required when both 1. a radio button (radioField) and 2. a cascading list (listField) meet a certain selection condition.

Here is my sample code in one of the Behaviours "Fields":

// set pointers to custom fields (list, radio button, and text)
def listField = getFieldByName ("My List")
def radioField = getFieldByName ("My Radio")
def textField = getFieldByName ("My Text")

// get cascading list value (parent and child)
String listString = listField.getValue()
// if cascading list matches one of two selections, show the radio button field
if ((listString == "[Parent1, Child1]") || (listString == "[Parent1, Child2]")) {
    radioField.setHidden(false)
} // otherwise, hide the radio button field
else {
    radioField.setHidden(true)
}
// get the value of the radio button field
String radioString = radioField.getValue()
// if both the cascading list and radio button value match specific values, make the text field required
if ((listString == "[Parent1, Child1]") && (radioString == "Radio Option")) {
    textField.setRequired(true)
}
// in all other cases, make the text field optional
else {
    textField.setRequired(false)
}

 

This code works except for making the text field required. I can get the text field to become required with the following steps:
1. Set listString to "[Parent1, Child2]"
2. Set radioString to "Radio Option"
3. Set list string to "[Parent1, Child1]"
In this case, we choose one list option that shows the radio button field but does not meet the conditions for making the text field required ("[Parent1, Child2]"). Then we can set the radio button to the correct option. Then set the list option to the one that meets the 2nd condition of making the text field required ("[Parent1, Child1]").

Given this behavior, it seems like the radio button field value is only being updated when I change the list field selection. But shouldn't it be independent of my list selection?

Additional information:
None of my radio buttons will update their value when I change the selection. I determined this by using log.warn on the radio button value and then checking the print statements in the last several lines of "atlassian-jira.log of the built-in script "View server log files". The radio button stays at its default.

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

102 views 1 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you