Single-Select Field Behave like Component/Versions with AJS

Hi,

I know a lot of people have asked in the past about multi-select field behaving like components/versions, but is it possible to get a single-select to behave like that as well?

When i try to edit the code, i have problems with it sticking or it will create duplicate fields

Multi-select solutions can be found:

https://answers.atlassian.com/questions/43534/can-i-have-multi-select-custom-field-behave-like-components-versions-fields

https://answers.atlassian.com/questions/62117/multiselect-fields-behaving-like-component-field-by-using-js-revisited?page=1#comment-65413

CK1's post:

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

1 answer

This widget could not be displayed.

Actually the code on

https://answers.atlassian.com/questions/43534

worked fine for my single-select list to behave like component/version (multiple choices possible).

If you have a single-select list and want it to behave like Priority (single choice) you can use AJS.SingleSelect instead of AJS.MultiSelect. Like:

<script type="text/javascript">
(function($){
    new AJS.SingleSelect({
        element: $("#customfield_10052"),
        itemAttrDisplayed: "label",
        errorMessage: AJS.params.multiselectComponentsError
    });
})(AJS.$);
</script>

 

You try this case: Multi-Select > Single-Select

<script type="text/javascript">
(function($) {
AJS.$("#customfield_10159 option[value='-1']").remove();
function convertMulti(id){
if (AJS.$('#'+id+"-field").length == 0){
new AJS.SingleSelect({
element: $("#"+id),
itemAttrDisplayed: "label",
errorMessage: AJS.params.multiselectComponentsError
});
}
}

AJS.toInit(function(){
convertMulti("customfield_10159");
})

JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
AJS.$("#customfield_10159 option[value='-1']").remove();
convertMulti("customfield_10159");
});
})(AJS.$);
</script>

 

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

97 views 1 0
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