Skip to content
Snippets Groups Projects
Commit 4e802252 authored by Bekerle, Patrizio's avatar Bekerle, Patrizio :fire: Committed by Reiter, Christoph
Browse files

Fix problem with initialization and last result

parent 37606117
No related branches found
No related tags found
No related merge requests found
...@@ -29,6 +29,7 @@ class PersonSelect extends VPULitElementJQuery { ...@@ -29,6 +29,7 @@ class PersonSelect extends VPULitElementJQuery {
this.value = ''; this.value = '';
this.ignoreValueUpdate = false; this.ignoreValueUpdate = false;
this.isSearching = false; this.isSearching = false;
this.lastResult = {};
} }
static get properties() { static get properties() {
...@@ -82,7 +83,6 @@ class PersonSelect extends VPULitElementJQuery { ...@@ -82,7 +83,6 @@ class PersonSelect extends VPULitElementJQuery {
initSelect2(ignorePreset = false) { initSelect2(ignorePreset = false) {
const that = this; const that = this;
const $this = $(this); const $this = $(this);
let lastResult = {};
if (this.jsonld === null) { if (this.jsonld === null) {
return false; return false;
...@@ -102,9 +102,11 @@ class PersonSelect extends VPULitElementJQuery { ...@@ -102,9 +102,11 @@ class PersonSelect extends VPULitElementJQuery {
return false; return false;
} }
// we need to destroy Select2 before we can initialize it again // we need to destroy Select2 and remove the event listeners before we can initialize it again
if (this.$select && this.$select.hasClass('select2-hidden-accessible')) { if (this.$select && this.$select.hasClass('select2-hidden-accessible')) {
this.$select.select2('destroy'); this.$select.select2('destroy');
this.$select.off('select2:select');
this.$select.off('select2:closing');
} }
this.$select.select2({ this.$select.select2({
...@@ -129,7 +131,7 @@ class PersonSelect extends VPULitElementJQuery { ...@@ -129,7 +131,7 @@ class PersonSelect extends VPULitElementJQuery {
}, },
processResults: function (data) { processResults: function (data) {
console.log(data); console.log(data);
lastResult = data; that.lastResult = data;
const results = that.jsonld.transformMembers(data, localContext); const results = that.jsonld.transformMembers(data, localContext);
...@@ -148,7 +150,7 @@ class PersonSelect extends VPULitElementJQuery { ...@@ -148,7 +150,7 @@ class PersonSelect extends VPULitElementJQuery {
}).on("select2:select", function (e) { }).on("select2:select", function (e) {
// set custom element attributes // set custom element attributes
const identifier = e.params.data.id; const identifier = e.params.data.id;
const object = findObjectInApiResults(identifier, lastResult); const object = findObjectInApiResults(identifier, that.lastResult);
$this.attr("data-object", JSON.stringify(object)); $this.attr("data-object", JSON.stringify(object));
$this.data("object", object); $this.data("object", object);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment