From 850e5a51b7a710e2ccbf80219aa3160f386c1da8 Mon Sep 17 00:00:00 2001 From: Luke Hudson Date: Fri, 19 Jun 2015 17:44:35 +0200 Subject: [PATCH] BUGFIX: Allow use on frontend 'Chosen' plugin assumed, but on front-end this is not a valid assumption. --- js/TagField.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/js/TagField.js b/js/TagField.js index 14c244c..49b9181 100644 --- a/js/TagField.js +++ b/js/TagField.js @@ -9,22 +9,28 @@ * we'll see an extra field where there should be only one. */ $.fn.chosenDestroy = function () { - $(this) - .show() // The field needs to be visible so Select2 evaluates the width correctly. - .removeClass('chzn-done') - .removeClass('has-chzn') - .next() - .remove(); - - return $(this); + var $this = $(this); + if ($this.siblings('.chzn-container').length) { + $this + .show() // The field needs to be visible so Select2 evaluates the width correctly. + .removeClass('chzn-done') + .removeClass('has-chzn') + .next() + .remove(); + } + return $this; }; $.entwine('ss', function ($) { - $('.ss-tag-field + .chzn-container').entwine({ + $('.ss-tag-field.has-chzn + .chzn-container, .ss-tag-field:not(.has-chzn)').entwine({ applySelect2: function () { var self = this, - $select = $(this).prev(); + $select = $(this); + + if ($select.prev().hasClass('ss-tag-field')) { + $select = $select.prev(); + } // There is a race condition where Select2 might not // be bound to jQuery yet. So here we make sure Select2