Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Make a custom field based on the selection on other field

Nikhil Srivastav May 14, 2013

I have multiselect field which is having some 40 value , I have a requirement that if the user select some fields from that field then i have to show the selected fields in a drop down field which will be another custom field jus below it .. I dont know how to do this ... Please let me know how can we do this (some js code in description becoz i dont want to use groovy here )

Thanks in Advance..

6 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Nikhil Srivastav May 19, 2013

I have done few modification and the code is working now :

<script type="text/javascript">
jQuery('#customfield_13181').change(function(){
  
  jQuery("#customfield_12981 option[value!='-1']").each(function() {
        jQuery(this).remove();
   });
  var options = [];
 
   jQuery('#customfield_13181 :selected').each(function(i, selected){
      
      options[i] = jQuery(selected).text();
     
   });
   
       
    var dList =jQuery('#customfield_12981')
    jQuery.each(options, function(index, item) {
   
    dList.append('<option>'+item+'</option>');
    
    });
   
 });

</script>

Nikhil Srivastav May 19, 2013

Hi,

I got one more error now :(

Its while submitting the request . I am selecting 4 values in the multi select field - say val1, val2,val3 ,val4

These are well generated in the next field but when i select the option val1, I get the below error:

Invalid value 'val1' passed for customfield 'Select field value'. Allowed values are: 50992[val4], 50993[val3], 50994[ val2 ], 50995[val1], -1

Please suggest

Nikhil Srivastav May 19, 2013

On further investigation i found that the id is not there with <option> tag not how can we add that. I have found this when i made another drop down field with some values... u can also check in the same way

Nadir MEZIANI
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.
May 19, 2013

Hi,

You could resolve this by :

1-create a dropdown list with the same values of multi select list

2-remove all values in drop down list which are not selected in multi select list

1 vote
Nadir MEZIANI
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.
May 20, 2013

Hi

This script work

<script type="text/javascript">
var dListOptions = [];
var mListOptions = [];
jQuery("#customfield_10201 option[value!='-1']").each(function(i, option){
dListOptions[i] = jQuery(option);
});
jQuery("#customfield_10201 option[value!='-1']").each(function() {
jQuery(this).remove();
});
jQuery('#customfield_10200').change(function(){
jQuery("#customfield_10201 option[value!='-1']").each(function() {
jQuery(this).remove();
});
jQuery('#customfield_10200 :selected').each(function(i, selected){
mListOptions[i] = jQuery(selected).text().trim();
});
jQuery(dListOptions).each(function (i,option){
if(jQuery.inArray(jQuery(option).text(),mListOptions)>-1){
jQuery("#customfield_10201").append(option);
}
})
});
</script>

Where

#customfield_10201 : the drop down list id 
#customfield_10200: the multi select list

0 votes
Robert Hall August 29, 2013

I'm working on something similar to this, I have one custom Jira field where the selection the user makes there will drive the selections on 3 other custom fields. I'm having some difficulty in making the linkage..if I have Jquery (or other javascript) that would need to fire when the first custom field value is selected (then use that selection to determine the options for the other fields), where would this javascript reside? In a js file deployed w/ my Custom Field plugin or in the configuration (admin page for custom fields) somewhere?

Nikhil Srivastav December 3, 2013

Hi Robert,

you can give your js or jquery code in the Description box of that custom field.

0 votes
Nadir MEZIANI
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.
May 15, 2013

Hi,

In jira 5.2.8 it' work like this:

in the description of your custom field :

jQuery('#multiselect field id').change(function(){
    jQuery("dropdown field id option[value!='-1']").each(function() {
        jQuery(this).remove();
    });
    var options = [];
    jQuery('#multiselect field id :selected').each(function(i, selected){
      options[i] = jQuery(selected).text();
    });
    var dList =jQuery('dropdown field id')
    jQuery.each(options, function(val, text) {
    dList.append(jQuery('&lt;option&gt;&lt;/option&gt;').val(val).html(text));
    });
});

screen

Nikhil Srivastav May 16, 2013

Hi,

I have added the below code in the drop down field :

&lt;script type="text/javascript"&gt;
jQuery('#customfield_ 13181').change(function(){
    jQuery("dropdown field id option[value!='-1']").each(function() {
        jQuery(this).remove();
    });
    var options = [];
    jQuery('#customfield_ 13181 :selected').each(function(i, selected){
      options[i] = jQuery(selected).text();
    });
    var dList =jQuery('#customfield_12981')
    jQuery.each(options, function(val, text) {
    dList.append(jQuery('&lt;option&gt;&lt;/option&gt;').val(val).html(text));
    });
});
&lt;/script&gt;

but when i select some options from the customfield 13181 (which is my multi select field) nothing happened. JIRA version is 5.2.4 but I dont think that will matter in this case. Please check

Nadir MEZIANI
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.
May 18, 2013

Hi,

you have omitted jQuery("dropdown field id option[value!='-1']").each(function() {

jQuery(this).remove();
});
replace dropdown field id with #customfield_12981
and the scitp is like this:
&lt;script type="text/javascript"&gt;
jQuery('#customfield_ 13181').change(function(){
    jQuery("#customfield_12981 option[value!='-1']").each(function() {
        jQuery(this).remove();
    });
    var options = [];
    jQuery('#customfield_ 13181 :selected').each(function(i, selected){
      options[i] = jQuery(selected).text();
    });
    var dList =jQuery('#customfield_12981');
    jQuery.each(options, function(val, text) {
    dList.append(jQuery('&lt;option&gt;&lt;/option&gt;').val(val).html(text));
    });
});
&lt;/script&gt;


0 votes
Nikhil Srivastav May 14, 2013

like i have a multiselect custom field with values - a1 a2 a3 a4 a5 a6 a7 a8 a9 a0;

suppose we select three options - a1 a3 a4

then the field which is drop down will be auto generated with the above 3 values (initially it was null)

0 votes
Nadir MEZIANI
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.
May 14, 2013

Hi,

You explain me more; values example

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events