From 0c2785f5c081d1e75e3576cea76acc5732e7e5fb Mon Sep 17 00:00:00 2001
From: Patrizio Bekerle <patrizio.bekerle@tugraz.at>
Date: Thu, 29 Aug 2019 11:10:07 +0200
Subject: [PATCH] Fix event loop

---
 packages/person-select/src/person-select.js | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/packages/person-select/src/person-select.js b/packages/person-select/src/person-select.js
index 3e981145..c9ac1c3b 100644
--- a/packages/person-select/src/person-select.js
+++ b/packages/person-select/src/person-select.js
@@ -26,6 +26,7 @@ class PersonSelect extends VPULitElementJQuery {
         // For some reason using the same ID on the whole page twice breaks select2 (regardless if they are in different custom elements)
         this.selectId = 'person-select-' + commonUtils.makeId(24);
         this.value = '';
+        this.ignoreValueUpdate = false;
     }
 
     static get properties() {
@@ -131,9 +132,9 @@ class PersonSelect extends VPULitElementJQuery {
 
             $this.attr("data-object", JSON.stringify(object));
             $this.data("object", object);
-            $this.val(identifier);
 
             if ($this.attr("value") !== identifier) {
+                that.ignoreValueUpdate = true;
                 $this.attr("value", identifier);
 
                 // fire a change event
@@ -192,9 +193,13 @@ class PersonSelect extends VPULitElementJQuery {
                     }
                     break;
                 case "value":
-                    if (this.$select !== null && this.$select.hasClass("select2-hidden-accessible")) {
+                    console.log("oldValue: " + oldValue);
+                    console.log("this.value: " + this.value);
+                    if (!this.ignoreValueUpdate && this.$select !== null && this.$select.hasClass("select2-hidden-accessible")) {
                         this.initSelect2();
                     }
+
+                    this.ignoreValueUpdate = false;
                     break;
                 case "entryPointUrl":
                     const that = this;
-- 
GitLab