Javascript create a custom value from two other values

art vandelay September 26, 2013

Hi All,

I am using the 3rd party multi cascading list and I would like to be able to take part of each selected value to create a custom text value.

For example, the selected values would be,

A. cascade select 1 | 1. cascade select 2 | a. cascade select 3

I would like to take the vales of each box, trucate, then add it to a custom field as

"A.1.a"

Any Thoughts?

thnaks

Art

4 answers

0 votes
art vandelay September 29, 2013

Thankyou for the link Rambanam, however I have struggled for two days to understand howthis works. Is there a step by step guide to getting the webresource plugin set up and then use the JS?

thanks

Art

RambanamP
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.
September 29, 2013
0 votes
RambanamP
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.
September 26, 2013

sample code i am giving here

<script type="text/javascript">
jQuery(document).ready(function($) {	
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {	
	getCascadingValue();
});
getCascadingValue();
function getCascadingValue(){		
		var multiselectValue=AJS.$('input[name=customfield_10100:0]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:1]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:2]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:3]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:4]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:5]:checked + label').text();		
		$('#customfield_10100:0').change(function() {
				multiselectValue=AJS.$('input[name=customfield_10100:0]:checked + label').text();
		});
		$('#customfield_10100:1').change(function() {
				multiselectValue=AJS.$('input[name=customfield_10100:0]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:1]:checked + label').text();
		});
		$('#customfield_10100:2').change(function() {
				multiselectValue=AJS.$('input[name=customfield_10100:0]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:1]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:2]:checked + label').text();
		});
		$('#customfield_10100:3').change(function() {
				multiselectValue=AJS.$('input[name=customfield_10100:0]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:1]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:2]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:3]:checked + label').text();
		});
		$('#customfield_10100:4').change(function() {
				multiselectValue=AJS.$('input[name=customfield_10100:0]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:1]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:2]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:3]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:4]:checked + label').text();
		});
		$('#customfield_10100:5').change(function() {
				multiselectValue=AJS.$('input[name=customfield_10100:0]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:1]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:2]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:3]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:4]:checked + label').text()+" "+AJS.$('input[name=customfield_10100:5]:checked + label').text();
		});	
		
		alert("MultiSelectValue"+multiselectValue);
}
	
});
</script>

art vandelay September 26, 2013

Thanks for the sample code, I will try over the weekend and revert back as soon as possible,

thanks again for the quick help.

Art

RambanamP
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.
September 26, 2013

i suggest load javascript as webresource module in plugin if you want to run this on create screen

https://developer.atlassian.com/display/JIRADEV/Web+Resource+Plugin+Module

0 votes
art vandelay September 26, 2013

Thanks for the quick feedback Rambanam,

It looks like the following

<div class="mlcs-customfield">
<div class="hidden mlcs-child-options">selectedValues=Object { customfield_10100:0="-1", customfield_10100:1="-1", customfield_10100:2="-1", more...}
<select id="customfield_10100:0" class="select" name="customfield_10100:0">
<option class="default-option" value="-1">Please select...</option>
<option class="mlcs-customfield-option" value="10100" data-parent-option-id=""> 1. Selection 1 </option>
</select>
<select id="customfield_10100:1" class="select" name="customfield_10100:1">
<option class="default-option" value="-1">Please select...</option>
<option class="mlcs-customfield-option" value="10101" data-parent-option-id="10100"> 1. Selection 2 a </option>
<option class="mlcs-customfield-option" value="10102" data-parent-option-id="10100"> 2. Selection 2 a </option>
</select>
<select id="customfield_10100:2" class="select" name="customfield_10100:2">
<option class="default-option" value="-1" selected="selected">Please select...</option>
<option class="mlcs-customfield-option" value="10106" data-parent-option-id="10102"> 1. Selection 3 a</option>
<option class="mlcs-customfield-option" value="10107" data-parent-option-id="10102"> 2. Selection 3 b </option>
</select>
<select id="customfield_10100:3" class="select" name="customfield_10100:3">
<option class="default-option" value="-1" selected="selected">Please select...</option>
<option class="mlcs-customfield-option" value="10108" data-parent-option-id="10106"> 1. Selection 4 a </option>
<option class="mlcs-customfield-option" value="10115" data-parent-option-id="10106"> 2. Selection 4 b </option>
</select>
<select id="customfield_10100:4" class="select" name="customfield_10100:4">
<option class="default-option" value="-1">Please select...</option>
<option class="mlcs-customfield-option" value="10109" data-parent-option-id="10108"> 1. Selection 5 a </option>
<option class="mlcs-customfield-option" value="10110" data-parent-option-id="10108"> 2. Selection 5 b </option>
<option class="mlcs-customfield-option" value="10111" data-parent-option-id="10108"> 3. Selection 5 c </option>
</select>
<select id="customfield_10100:5" class="select" name="customfield_10100:5">
<option class="default-option" value="-1" selected="selected">Please select...</option>
<option class="mlcs-customfield-option" value="10112" data-parent-option-id="10111"> 1. Selection 6 a </option>
<option class="mlcs-customfield-option" value="10113" data-parent-option-id="10111"> 2. Selection 6 b </option>
<option class="mlcs-customfield-option" value="10114" data-parent-option-id="10111"> 3. Selection 6 c </option>
</select>
</div>

<div class="field-group">
<label for="customfield_10108">FS_Notes</label>
<textarea id="customfield_10108" class="textarea long-field" rows="5" name="customfield_10108" cols="40"></textarea>
<div class="description">Functional Spec Notes</div>
</div>

So I am trying to get customfield_10108 to be

1.2.1.1.3.1

based on the following cascadding choice

<option class="mlcs-customfield-option" value="10100" data-parent-option-id=""> 1. Selection 1 </option>
<option class="mlcs-customfield-option" value="10102" data-parent-option-id="10100"> 2. Selection 2 a </option>
<option class="mlcs-customfield-option" value="10106" data-parent-option-id="10102"> 1. Selection 3 a</option>
<option class="mlcs-customfield-option" value="10108" data-parent-option-id="10106"> 1. Selection 4 a </option>
<option class="mlcs-customfield-option" value="10111" data-parent-option-id="10108"> 3. Selection 5 c </option>
<option class="mlcs-customfield-option" value="10112" data-parent-option-id="10111"> 1. Selection 6 a </option>

Thanks again for your offer to help,

Art

0 votes
RambanamP
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.
September 26, 2013

can you share me the source(id's, you can check this by using firebug in firefox ) of the multi cascading field? so can able to give solution

Suggest an answer

Log in or Sign up to answer