Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Hide "None"-option on radio buttons

Mattias Kallvi
Contributor
December 7, 2018

Hi all,

I have a radio button field on which I want to hide the None-option.

  • I can't make it mandatory since the users will not know what to fill in when they create the issue.
  • I can't do a global change on the server since I want the None-option on some other fields

I have read through a lot of posts saying that I should use Scriptrunners Behaviours. So, I created a behaviour, added a Initializor and this is where I get stuck. How do I remove the None-option? Anyone who has done this and has some working example to share? I really need some help here.

Best regards

Mattias

2 answers

1 accepted

5 votes
Answer accepted
Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 12, 2018

Hi Mattias,

I think you can just collect all of the options for a field and then use the setFieldOptions method to set the options for the field. When all the options for a field are collected, I believe that "None" will automatically be excluded, so "None" will no longer be a choice after setting the options for the field.

I've not tested this, but it should look something like this:

import com.atlassian.jira.component.ComponentAccessor

//Grab appropriate managers
def cfManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()

//Grab form and custom field values
def selectCF = cfManager.getCustomFieldObject("SelectListA")
def selectField = getFieldByName("SelectListA")

//Must grab the relevant config given the current issue context and the custom field
def config = selectCF.getRelevantConfig(getIssueContext())
//Given config, grab a map of the possible options for the select custom field
def options = optionsManager.getOptions(config)

//Define preset multi select options for each single select case
selectField.setFieldOptions(options.collectEntries{[(it.optionId): it.value]})

Of course you'll want to change "SelectListA" in this script to the actual name of your field.

Regards,

Josh

Mattias Kallvi
Contributor
December 13, 2018 edited

Hi Joshua,

Thanks for your script. After a minor change to it (used the field id instead of the field name) it works perfectly. Maybe I have to use id since we have Swedish characters in the field name, not sure. However, this is how thoses lines look now:

…
//Grab form and custom field values
def selectCF = cfManager.getCustomFieldObject("customfield_12345")
def selectField = getFieldById("customfield_12345")
…

Once again, thanks for your help!

Regards
Mattias

Like • Krasimir BOEV likes this
Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 13, 2018

Glad to hear you got it working. Thx for using ScriptRunner!

Manuel
Contributor
May 27, 2019

The script is still working fine - thanks!

Is it also possible to hide entries / elements of a the radio buttons field like "do not show last option of the list"?

 

Best Regards

Manuel

0 votes
Sumedh Ganta June 10, 2019

Hi Joshua Yamdogo @ Adaptavist 

 

I tried the script you provided. Where do I add the field options? I used the script as is and none still appears to me. Can you please help me with it?

 

My field options are yes and no. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events