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

Fix unselecting if not found

parent 3e7cc322
No related branches found
No related tags found
No related merge requests found
...@@ -27,6 +27,7 @@ class PersonSelect extends VPULitElementJQuery { ...@@ -27,6 +27,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) // 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.selectId = 'person-select-' + commonUtils.makeId(24);
this.value = ''; this.value = '';
this.object = null;
this.ignoreValueUpdate = false; this.ignoreValueUpdate = false;
this.isSearching = false; this.isSearching = false;
this.lastResult = {}; this.lastResult = {};
...@@ -40,12 +41,16 @@ class PersonSelect extends VPULitElementJQuery { ...@@ -40,12 +41,16 @@ class PersonSelect extends VPULitElementJQuery {
active: { type: Boolean, attribute: false }, active: { type: Boolean, attribute: false },
entryPointUrl: { type: String, attribute: 'entry-point-url' }, entryPointUrl: { type: String, attribute: 'entry-point-url' },
value: { type: String }, value: { type: String },
object: { type: Object, attribute: false },
showReloadButton: { type: Boolean, attribute: 'show-reload-button' }, showReloadButton: { type: Boolean, attribute: 'show-reload-button' },
reloadButtonTitle: { type: String, attribute: 'reload-button-title' }, reloadButtonTitle: { type: String, attribute: 'reload-button-title' },
}; };
} }
clear() { clear() {
this.object = null;
$(this).attr("data-object", "");
$(this).data("object", null);
this.$select.val(null).trigger('change').trigger('select2:unselect'); this.$select.val(null).trigger('change').trigger('select2:unselect');
} }
...@@ -158,10 +163,10 @@ class PersonSelect extends VPULitElementJQuery { ...@@ -158,10 +163,10 @@ 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, that.lastResult); that.object = findObjectInApiResults(identifier, that.lastResult);
$this.attr("data-object", JSON.stringify(object)); $this.attr("data-object", JSON.stringify(that.object));
$this.data("object", object); $this.data("object", that.object);
if ($this.attr("value") !== identifier) { if ($this.attr("value") !== identifier) {
that.ignoreValueUpdate = true; that.ignoreValueUpdate = true;
...@@ -201,6 +206,7 @@ class PersonSelect extends VPULitElementJQuery { ...@@ -201,6 +206,7 @@ class PersonSelect extends VPULitElementJQuery {
return result.json(); return result.json();
}) })
.then((person) => { .then((person) => {
that.object = person;
const identifier = person["@id"]; const identifier = person["@id"];
const option = new Option(person.name, identifier, true, true); const option = new Option(person.name, identifier, true, true);
$this.attr("data-object", JSON.stringify(person)); $this.attr("data-object", JSON.stringify(person));
...@@ -214,7 +220,9 @@ class PersonSelect extends VPULitElementJQuery { ...@@ -214,7 +220,9 @@ class PersonSelect extends VPULitElementJQuery {
}, },
bubbles: true bubbles: true
})); }));
}).catch(() => {}); }).catch(() => {
that.clear();
});
} }
return true; return true;
...@@ -252,7 +260,7 @@ class PersonSelect extends VPULitElementJQuery { ...@@ -252,7 +260,7 @@ class PersonSelect extends VPULitElementJQuery {
} }
reloadClick() { reloadClick() {
if (this.value === "") { if (this.object === null) {
return; return;
} }
...@@ -324,7 +332,7 @@ class PersonSelect extends VPULitElementJQuery { ...@@ -324,7 +332,7 @@ class PersonSelect extends VPULitElementJQuery {
</div> </div>
<a class="control button" <a class="control button"
id="reload-button" id="reload-button"
?disabled=${this.value === ""} ?disabled=${this.object === null}
@click="${this.reloadClick}" @click="${this.reloadClick}"
style="display: ${this.showReloadButton ? "flex" : "none"}" style="display: ${this.showReloadButton ? "flex" : "none"}"
title="${this.reloadButtonTitle}"> title="${this.reloadButtonTitle}">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment