Multiselect Fields behaving like Component Field by using JS *Revisited*

Hi,

I'm referring to this Q : https://answers.atlassian.com/questions/43534/can-i-have-multi-select-custom-field-behave-like-components-versions-fields

The thing is: All work fine, until you change the Issue Type while editing the Issue, then the Field reverts back to plain multiselect.

Is there a way to modify the JS to stop this behavior?

@Jamie Echlin : Pretty please...:-)

14 answers

1 accepted

Accepted Answer
8 votes

Here solution, that works for me

<script type="text/javascript">
(function($) {

    AJS.toInit(function(){
        // init element on load
        new AJS.MultiSelect({
            element: $("#customfield_10200"),
            itemAttrDisplayed: "label",
            errorMessage: AJS.params.multiselectComponentsError
        });
    })

    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
        // init element on refresh
        new AJS.MultiSelect({
            element: $("#customfield_10200"),
            itemAttrDisplayed: "label",
            errorMessage: AJS.params.multiselectComponentsError
        });
    });

})(AJS.$);

</script>

Hi Grigory - Thanks a lot! That did work...however...

If I close the issue popup and open it again without reloading the whole page by browser refresh, I get the following phenomenon:

The input box multiplies depending on how often I open/close the popup (see screen below)

this seems releted to the "JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED.." part, since removing this part fixes the issue (or maybe its the init of the 2 elements)

Any idea how to fix this bugger? (getting so close now!)

1000 x thanks in advance....

Here you go:

<script type="text/javascript">
(function($) {

    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_10200");
    })

    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
        convertMulti("customfield_10200");
    });

})(AJS.$);

</script>

Hope, it helped :)

Hi Grigory ,

yes, that finally did the job!

Thanks a lot, big Karma reward from me...;-)

For future reference - The whole thing (with removal of the "None" value).

<script type="text/javascript">
(function($) {
 
 // "customfield_10400" 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_10400 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_10400");
    })
 
    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
        AJS.$("#customfield_10400 option[value='-1']").remove();
		convertMulti("customfield_10400");
    });
 
})(AJS.$);
</script>

Thanks again...

Cheers,

Chris

first, Project A has custom field with the above script in description. Project B does not have that custom field.

So, When im at dashboard, and click create project, by default if it starts with attempting to create issue in project B(as that was the last project i was navigating) but i switch so that i want issue to be created in project A, my multi select option in Project A looks like the original multi select(the script has not had any effect)

This does work correctly for me however, if i navigate to Project A, then click on create issue.

I hope this makes sense.

Is it possible to adapt code to work for this problem?

Grigory!!! You're a freaking genious!!!!!! Thank you so much. You rock big time!

0 votes
Mizan Community Champion Jun 13, 2012

What happens when you dont change Issue type and change some other field or just refresh , did you check if this occurs on other browsers too ?

Hi Mizan,

only when I change the Isssue Type, since that seems to prompt reloading of the window.

Reloading by browser is not possible since that closes the window

Browsers: IE 8 and Firefox 12 - The same...

Maybe you can try to listen for NEW_CONTENT_ADDED event and paste multiselect transformation code there?

(function($) {
    
    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
        >>PASTE-CODE-HERE<<
    });

})(AJS.$);

There was a bug, that this event didn't triggered on early 5 version, but I saw that it was fixed.

Hello Grigory, below is the code I use to *almost* sucessfully mask the multiselect field:

AJS.$("#customfield_10400 option[value='-1']").remove(); (function($){ new AJS.MultiSelect({ element: $("#customfield_10400"), itemAttrDisplayed: "label", errorMessage: AJS.params.multiselectComponentsError }); })(AJS.$);

I tried something like:

(function($) {
   
    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
       (function($){
    new AJS.MultiSelect({
        element: $("#customfield_10400"),
        itemAttrDisplayed: "label",
        errorMessage: AJS.params.multiselectComponentsError
    });
})
    });

})(AJS.$);

Result: Nothing works, the Field is not masked at all

- JS Noob-1 here - What did I do wrong?

Nobody knows how to do this? Come on guys - The searcheable MS is sooo much better than the plain one - especially when dealing with 50+ values...

0 votes
Mizan Community Champion Jun 25, 2012

How have you applied your script ? i mean have you pasted it in the field configuration>>field description ?

Try to check what happens when the script is placed in the announcement banner

Hi Mizan,

I sure did that - however the result was: nothing at all happened - no masking.

So I guess somethings wrong: Either in the code itself or the wrong listener.

0 votes
Mizan Community Champion Jun 26, 2012

You are saying that when you create an issue you select the project then the issue type then click on next , then you fill the details . at this time the field behaves like a component field until you change the issue type , right ?

Hi Mizan,

yes, exactly. But the script Grigory posted fixes this. Unfortunately this introduces another Glitch (see below)...

Hi,

would someone please post the edit.vm file. I couldn't get this to work.

Thanks very much.

first, Project A has custom field with the above script in description. Project B does not have that custom field.

So, When im at dashboard, and click create project, by default if it starts with attempting to create issue in project B(as that was the last project i was navigating) but i switch so that i want issue to be created in project A, my multi select option in Project A looks like the original multi select(the script has not had any effect)

This does work correctly for me however, if i navigate to Project A, then click on create issue.

I hope this makes sense.

Is it possible to adapt code to work for this problem?

Hi guys,

I have got the same problem as Michal Crkon. Does anybody has an update about this?

Cheers, Björn

Hi,

I am facing the same issue as described by Michal Crkon in the comment mentioned above:

Project A has custom field with the javascript for multiselect in description. Project B does not have that custom field.

So, When im at dashboard, and click create project, by default if it starts with attempting to create issue in project B(as that was the last project i was navigating) but i switch so that i want issue to be created in project A, my multi select option in Project A looks like the original multi select.

Please let me know if there is anyway to resolve this ?

Thanks,

Karan

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 16, 2018 in Jira

Looking for anyone who made the switch to Data Center

The Jira Marketing team is putting together an ebook on migrating to Data Center. We're looking for pro tips on how you staffed your project team and organized your Proof of Concept. Share yo...

74 views 0 3
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you