Join 34,000+ subscribers and receive articles from our
blog about software quality, testing, QA and security.

Saving results from Dynamic Dropdowns when editing a Test Case


#1

I have a sequence of dynamic dropdowns for classifying test cases.
My problem is the results are not saved when in click on the save test case button. Help?

$(document).ready(function() {

var active_key = "";
var active_inx = "";

$("#custom_main_feature").change(function() {

	var sel = document.getElementById("custom_main_feature");
	var text = sel.options[sel.selectedIndex].text; 
	active_key = text;
            active_inx = sel.selectedIndex;
		  
	//These second level keys are used to populate the component 'feature'
	var feature_keys = Object.keys(featurelist[text]);
		  
	//Remove options for feature
	var $secondChoice = $("#custom_feature");
	$secondChoice.empty();

	//Append New Options for Secondary - value and index should be the same
	$.each(feature_keys, function(fkey) {
		if (fkey == 0) {
			$secondChoice.append("<option value=\"" + fkey + "\" selected=\"selected\">" + feature_keys[fkey] + "</option>");
		} else {
			$secondChoice.append("<option value=\"" + fkey + "\">" + feature_keys[fkey] + "</option>");
		}
	});

	//Remove options for sub_feature
	var $tertiaryChoice = $("#custom_sub_feature");
	$tertiaryChoice.empty();
});


//If the secondary dropdown changes, clear out and repopulate the tertiary dropdown
    var  text2 = "";
    var  inx2 =  "";

$("#custom_feature").change(function() {
	  
	var sel2 = document.getElementById("custom_feature");
	text2 = sel2.options[sel2.selectedIndex].text;
            inx2 = sel2.selectedIndex;
		  
	//These second level keys are used to populate the component 'feature'
            var feature_keys = Object.keys(featurelist[active_key]);

	//Remove options for feature
	var $secondChoice = $("#custom_feature");
	$secondChoice.empty();

	//Append New Options for Secondary - value and index should be the same
	$.each(feature_keys, function(fkey) {
		if (fkey == inx2) {
			$secondChoice.append("<option value=\"" + fkey + "\" selected=\"selected\">" + feature_keys[fkey] + "</option>");
		} else {
			$secondChoice.append("<option value=\"" + fkey + "\">" + feature_keys[fkey] + "</option>");
		}
	});

	//List of Teriary Dropdown Values
	var tertiary_arr = featurelist[active_key][text2];
		  
	//Remove options for feature
	var $tertiaryChoice = $("#custom_sub_feature");
	$tertiaryChoice.empty();

	//Append New Options - value and index should be the same
	$.each(tertiary_arr, function(tkey) {
		if (tkey == 0) {
			$tertiaryChoice.append("<option value=\"" + tkey + "\" selected=\"selected\">" + tertiary_arr[tkey] + "</option>");
		} else {
			$tertiaryChoice.append("<option value=\"" + tkey + "\">" + tertiary_arr[tkey] + "</option>");
		}
	});
});

//If the tertiary dropdown changes, clear out and repopulate the tertiary dropdown
$("#custom_sub_feature").change(function() {
	  
	var sel3 = document.getElementById("custom_sub_feature");
	var text3 = sel3.options[sel3.selectedIndex].text;
	var inx3 = sel3.selectedIndex;

	//List of Teriary Dropdown Values
	var tertiary_arr = Object.keys(featurelist[active_key][text2]);
		  
	//Remove options for sub feature dropdown list
	var $tertiaryChoice = $("#custom_sub_feature");
	$tertiaryChoice.empty();

	//Append New Options - use selected index for 'selected', if none use '1'
	$.each(tertiary_arr, function(tkey) {	
		if (tkey == inx3) {
			$tertiaryChoice.append("<option value=\"" + tkey + "\" selected=\"selected\">" + tertiary_arr[tkey] + "</option>");
		} else {
			$tertiaryChoice.append("<option value=\"" + tkey + "\">" + tertiary_arr[tkey] + "</option>");
		}
	});
});

});

PS. Right now the javascript is not optimal and I plan on fixing it after I understand a few more details better.


#2

Hi Laurie,

Thanks for your posting. Where do you store the actual dropdown values? Have you also configured the values for the field in TestRail under Administration > Customizations?

Cheers,
Tobias


#3

Right before the javascript is a large json data set for the dropdowns (I’ve attached a text version of everything on the page). The three dropdowns are custom with only the main (top) level containing a list of values defined in the custom dropdown. The other two (middle and bottom) only have NA set as values and are populated on the fly.

Laurie Salopek
Senior Quality Assurance Engineer
Direct: x2407
lsalopek@hiperos.commailto:lsalopek@hiperos.com

[cid:image001.jpg@01D1F485.BA72ABC0]


#4

Hi Laurie,

Thanks for your reply. This wouldn’t work as TestRail also needs to know the values (in order to display them on other pages) and configuring them as part of the custom field options would be required. In general, we don’t recommend larger customizations like yours with UI scripts and there are often better ways to implement things. In your case, I would simply recommend one large dropdown field and structuring the values as follows:

A > 1 > a
A > 1 > b
A > 1 > c
A > 2 > a
A > 2 > b
B > 5 > f

etc.

Would this work for you?

Cheers,
Tobias


#5

Unfortunately, your suggestion would not work since the list would be lengthy and difficult to use.

Thank you for your time.

Laurie Salopek
Senior Quality Assurance Engineer
Direct: x2407
lsalopek@hiperos.commailto:lsalopek@hiperos.com

[cid:image001.jpg@01D1F485.BA72ABC0]


#6

Hi Laurie,

Thanks for your reply and I’m sorry to hear that. We are happy to look into built-in support for cascading dropdowns and we recommend the approach in my previous reply in the meantime.

Cheers,
Tobias


#7

Thank you for all your help and yes, implementing dynamic dropdowns would be a great benefit for us. In the meantime, the team has decided to go with your suggestion and I will be building up that LONG list soon :slight_smile:

Laurie Salopek
Senior Quality Assurance Engineer
Direct: x2407
lsalopek@hiperos.commailto:lsalopek@hiperos.com

[cid:image001.jpg@01D1F485.BA72ABC0]


#8

Great to hear that this helped, I hope the list isn’t too much work :slight_smile:

Cheers,
Tobias


#9

It is done, but MONSTEROUS :wink:

Please rescue our QA group by implementing dynamic dropdowns :slight_smile:

Laurie Salopek
Senior Quality Assurance Engineer
Direct: x2407
lsalopek@hiperos.commailto:lsalopek@hiperos.com

[cid:image001.jpg@01D1F485.BA72ABC0]


#10

Will look into it, thanks again for your feedback Laurie :slight_smile:

Cheers,
Tobias


#11

Thank you for listening!

Laurie Salopek
Senior Quality Assurance Engineer
Direct: x2407
lsalopek@hiperos.commailto:lsalopek@hiperos.com

[cid:image001.jpg@01D1F485.BA72ABC0]


#12

Sure, and thanks again :slight_smile:

Cheers,
Tobias