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