Pre-selecting MultiSelect with default value using Behaviours plugin

Andrew Lee August 24, 2014

Hello.

We have a multi select list in our transition screen where it is pre-selected according to the selected values in the same select list in the parent Jira.

In Behaviour plugin, we pre-select the select list by using setFormValue function. It works but what we would like to do is displaying and converting the multi select list to an auto complete multi picker.

We use the following code to convert the select list into a auto complete multi picker by pasting the lines in the description field.

<script type="text/javascript">
(function($) {
 // "customfield_11315" is the number of the custom 
 // multiselect field you want to change as e.g. 
 // seen at the end of the "configure" page url of 
 // the field you want to change this way 
    AJS.$("#customfield_11315 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_11315");
    })
    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
        AJS.$("#customfield_11315 option[value='-1']").remove();
        convertMulti("customfield_11315");
    });
})(AJS.$);
</script>

The problem here is that the auto complete multi picker doesn't display the pre-selected by the Behaviours plugin (setFormValue) in its text area. The pre-selected values aren't available in auto comlete multi picker's available (unselected) dropdown list either.. so i assume the values are actually selected but just are not displayed correctly in the multi picker's text area.

Has anyone else come across with this issue? I wonder if I could get the pre-selected option values correctly displayed in the auto complete multi picker's text area by tweaking the javascript above?

Thank you in advance!

2 answers

0 votes
Andrew Lee August 24, 2014

Worked it out by manually setting "selected" property to the option values via jQuery script before converting the select list to auto complete multi select picker :)

Mohd Adnan January 20, 2015

it will be great if you share your solution here.

0 votes
Andrew Lee August 24, 2014

I suppose I must rephrase my question..

Is it possible to pre-select auto complete multi select picker and pre-populate the selected options?

Suggest an answer

Log in or Sign up to answer