From 7e2cf03a2699594807b0f9164b68221d277befc2 Mon Sep 17 00:00:00 2001 From: Michael Schock Date: Thu, 1 Mar 2018 17:01:16 -0800 Subject: [PATCH] STRF-4496 - Fix product options unhiding indexing issue --- CHANGELOG.md | 1 + assets/js/theme/common/select-option-plugin.js | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8366e15585..33d4e315ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## Draft +- Fix product options unhiding indexing issue. [#1176](https://github.com/bigcommerce/cornerstone/pull/1176) ## 1.13.2 (2018-02-28) diff --git a/assets/js/theme/common/select-option-plugin.js b/assets/js/theme/common/select-option-plugin.js index d4575ec226..63c6d6c9b2 100644 --- a/assets/js/theme/common/select-option-plugin.js +++ b/assets/js/theme/common/select-option-plugin.js @@ -41,10 +41,12 @@ function toggleOption(show) { // move the option to the correct select element if required if (currentSelectElement.is(':disabled') && show) { const previousIndex = this.data('index'); - if (previousIndex > 0) { - this.insertAfter(selectElement.find(`option:eq(${previousIndex - 1})`)); + const $elementNowAtPreviousIndex = selectElement.find(`option:eq(${previousIndex})`); + + if ($elementNowAtPreviousIndex.length) { + this.insertBefore($elementNowAtPreviousIndex); } else { - $(this).prependTo(selectElement); + $(this).appendTo(selectElement); } } else if (!currentSelectElement.is(':disabled') && !show) { this.data('index', currentSelectElement.find('option').index(this));