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

CK1 June 13, 2012

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

8 votes
Answer accepted
grundic
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.
June 26, 2012

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>

CK1 June 26, 2012

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....

grundic
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.
June 26, 2012

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 :)

CK1 June 26, 2012

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

Like MrZhuct likes this
Michal Crkon July 2, 2013

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?

Michael Brinson November 19, 2014

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

0 votes
Karanpreet Kaur April 25, 2016

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

 

0 votes
Björn Frauen _STAGIL_ July 29, 2014

Hi guys,

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

Cheers, Björn

0 votes
Michal Crkon July 2, 2013

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?

0 votes
Björn Bung November 24, 2012

Hi,

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

Thanks very much.

0 votes
CK1 June 26, 2012

Hi Mizan,

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

0 votes
Mizan
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.
June 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 ?

0 votes
CK1 June 26, 2012

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
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.
June 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

0 votes
CK1 June 25, 2012

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
CK1 June 24, 2012
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?

0 votes
grundic
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.
June 24, 2012

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.

0 votes
CK1 June 24, 2012

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...

0 votes
Mizan
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.
June 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 ?

Suggest an answer

Log in or Sign up to answer