How to enable Autocomplete Renderer for Multi-Select Custom Field in JIRA

Still need help?

The Atlassian Community is here for you.

Ask the community

The information in this page relates to customizations in JIRA. Consequently, Atlassian Support cannot guarantee to provide any support for the steps described on this page as customizations are not covered under Atlassian Support Offerings. Please be aware that this material is provided for your information only and that you use it at your own risk.

Also, please be aware that customizations done by directly modifying files are not included in the upgrade process. These modifications will need to be reapplied manually on the upgraded instance.

Platform Notice: Server and Data Center Only - This article only applies to Atlassian products on the server and data center platforms.

Purpose

The purpose of this article is to show how to change the default renderer (Select List Renderer) on a Multi-Select Custom Field to use the Autocomplete Renderer without changing JIRA's source code. This can be done by adding JavaScript to the custom field's description.

This document will give you more details on how to work with Custom Fields in JIRA. 

Solution

  1. Go to Administration > Issues > Custom Fields;
  2. Create a Custom Field of type "Select List (multiple choices)".
  3. Click on the 'cog' icon on the right side of the newly-created custom field and click Edit;
  4. Add the below code to the Description field and click Update;

    <script type="text/javascript">
    (function($) {
        AJS.$("#customfield_<cf-id> option[value='-1']").remove(); //Removes the default value "None"
        function convertMulti(id){
            if (AJS.$('#'+id+"-textarea").length == 0){
                new AJS.MultiSelect({
                    element: $("#"+id),
                    itemAttrDisplayed: "label",
                    errorMessage: AJS.params.multiselectComponentsError
                });
            }
        }
      
        AJS.toInit(function(){ 
            convertMulti("customfield_<cf-id>");
        })
      
        JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
            AJS.$("#customfield_<cf-id> option[value='-1']").remove();
            convertMulti("customfield_<cf-id>");
        });
    })(AJS.$);
    </script>

    (info) Replace <cf-id> with the ID of the custom field you're modifying. You can get this information by running the below query on JIRA's database. For example, if the ID is 10100, you'll have to change customfield_<cf-id> to customfield_10100.

    SELECT id FROM customfield WHERE cfname = '<cf-name>';

    (info) Replace <cf-name> with the name of the custom field you're modifying.

Last modified on Jun 2, 2016

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.