Forums

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

I removed some JavaScript from a custom field, but it is still shown on the create issue screen

Craig Goulden
Contributor
July 28, 2020

To get a multi-select custom field to behave like system multi-select fields with type-ahead and lozenges I added this JavaSecript to the Description of the field:

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

// "customfield_11301" 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_11301 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_11301"); }

)

JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context)

{ AJS.$("#customfield_11301 option[value='-1']").remove(); convertMulti("customfield_11301"); }

);

})(AJS.$);
</script>

This worked for years, but stopped working after upgrading to Data Centre version 8.9.1. The JavaScript was just shown in text under the field in the Create Issue screen.

I found I could get the desired behaviour for multi-select fields by installing a plugin, select2 from https://marketplace.atlassian.com/apps/1220214/select2?hosting=datacenter&tab=overview

The problem remaining is that after deleting the JavaScript from the description, it is still being displayed under the field in the Create Issue screen. I tried re-indexing, but the JavaScript is still displayed although it is no longer in the Description field.

 

1 answer

1 accepted

0 votes
Answer accepted
Nic Brough -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.
July 28, 2020

Oddly, field descriptions may be held in two places.

I'd guess you removed the data from Admin -> Issues -> Custom fields -> That field ->

The script might also be lurking in the project data.  Go to the project where the issue is still showing it on create and go to project admin -> field configuration scheme -> field configuration for that issue type -> find your field and check the field description there.

Craig Goulden
Contributor
July 28, 2020

You're a champion, Nic. That was the problem.

I'll buy you a beer the next time you're in Sydney :-)

Nic Brough -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.
July 29, 2020

It's an obscure one!  Glad to help!

sandosh_vaidyanathan3 March 6, 2024

Hi @Nic Brough  We are having the simillar issue post upgrade multiselect value is not able to disable the available value ex. 

AJS.$("#customfield_13704 option[value='-1']").remove();  which used to work , now no longer works. Any thoughts on how this can be resolved?

Nic Brough -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.
March 7, 2024

Atlassian are gradually removing the ability to inject javascript through field descriptions, so I'd recommend you look at a different way to do it.

Suggest an answer

Log in or Sign up to answer