From 15d6a5849e2ccab1561724298d94552ad769ae25 Mon Sep 17 00:00:00 2001 From: Julian Gonggrijp Date: Thu, 29 Jul 2021 12:28:24 +0200 Subject: [PATCH] Only destroy select2 element if initialized (#486 #465 #426) --- frontend/src/forms/select2-picker-view.ts | 11 +++++++++-- frontend/src/semantic-search/dropdown-view.ts | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/frontend/src/forms/select2-picker-view.ts b/frontend/src/forms/select2-picker-view.ts index 79b70230..ef71452b 100644 --- a/frontend/src/forms/select2-picker-view.ts +++ b/frontend/src/forms/select2-picker-view.ts @@ -7,7 +7,7 @@ import BasePicker from './base-picker-view'; */ export default class Select2PickerView extends BasePicker { beforeRender(): this { - this.$('select').select2('destroy'); + this.destroySelect(); return this; } @@ -16,8 +16,15 @@ export default class Select2PickerView extends BasePicker { return this; } + destroySelect(): void { + const select = this.$('select'); + if (select.hasClass('select2-hidden-accessible')) { + select.select2('destroy'); + } + } + remove(): this { - this.$('select').select2('destroy'); + this.destroySelect(); return super.remove(); } diff --git a/frontend/src/semantic-search/dropdown-view.ts b/frontend/src/semantic-search/dropdown-view.ts index f3e7fd0d..76dbe255 100644 --- a/frontend/src/semantic-search/dropdown-view.ts +++ b/frontend/src/semantic-search/dropdown-view.ts @@ -221,4 +221,5 @@ extend(Dropdown.prototype, { val: BasePicker.prototype.val, open: Select2Picker.prototype.open, beforeRender: Select2Picker.prototype.beforeRender, + destroySelect: Select2Picker.prototype.destroySelect, });