From e52277bdad6d45420284109819f6b6b09934dd41 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Wed, 21 Dec 2016 13:15:55 +0100 Subject: [PATCH 1/2] Fix sample types & groups when editing sample in samples table Closes SCI-811. --- app/assets/javascripts/sitewide/utils.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/sitewide/utils.js b/app/assets/javascripts/sitewide/utils.js index 50224bb57..ed6fd8aa1 100644 --- a/app/assets/javascripts/sitewide/utils.js +++ b/app/assets/javascripts/sitewide/utils.js @@ -239,8 +239,10 @@ $.fn.makeDropdownOptionsLinks = function(selectedIdx, urlParam) { } else { $(this).attr('href', '#'); } - }) - .eq(selectedIdx).attr('selected', true); + }); + $(this) + .find('option[value=' + selectedIdx + ']') + .attr('selected', true); return this; }; From af6bf2aee1fc938a2cc9e259b2a00c6db462e59f Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Wed, 21 Dec 2016 16:23:09 +0100 Subject: [PATCH 2/2] Fix jQuery selector, make it work for new samples --- app/assets/javascripts/sitewide/utils.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/sitewide/utils.js b/app/assets/javascripts/sitewide/utils.js index ed6fd8aa1..3c7a094cb 100644 --- a/app/assets/javascripts/sitewide/utils.js +++ b/app/assets/javascripts/sitewide/utils.js @@ -225,7 +225,7 @@ function initPageTutorialSteps(pageFirstStepN, pageLastStepN, nextPagePath, * @return {Object} This */ $.fn.makeDropdownOptionsLinks = function(selectedIdx, urlParam) { - selectedIdx = _.isUndefined(selectedIdx) ? 1 : selectedIdx; + selectedIdx = _.isUndefined(selectedIdx) ? -1 : selectedIdx; $(this).change(function() { window.location.href = addParam($(this).find('option:selected') @@ -240,9 +240,11 @@ $.fn.makeDropdownOptionsLinks = function(selectedIdx, urlParam) { $(this).attr('href', '#'); } }); - $(this) - .find('option[value=' + selectedIdx + ']') - .attr('selected', true); + var selectedOpt = $(this).find('option[value="' + selectedIdx + '"]'); + if (!selectedOpt.length) { + selectedOpt = $(this).find('option').eq(1); + } + selectedOpt.attr('selected', true); return this; };