From 74a8872eada1b7dad3e35a9363f12dca7345a489 Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 16 Nov 2023 10:09:20 -0700 Subject: [PATCH] Fix missing value in some static option selects Shoelace select initially rejects the value due to missing option, and needs to be re-set once our options have arrived --- api/js/etemplate/Et2Select/Select/Et2SelectAccount.ts | 1 + api/js/etemplate/Et2Select/Select/Et2SelectCategory.ts | 6 ++++++ api/js/etemplate/Et2Select/StaticOptions.ts | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/api/js/etemplate/Et2Select/Select/Et2SelectAccount.ts b/api/js/etemplate/Et2Select/Select/Et2SelectAccount.ts index e92f9b0ecd..ecb4582e51 100644 --- a/api/js/etemplate/Et2Select/Select/Et2SelectAccount.ts +++ b/api/js/etemplate/Et2Select/Select/Et2SelectAccount.ts @@ -91,6 +91,7 @@ export class Et2SelectAccount extends SelectAccountMixin(Et2StaticSelectMixin(Et return Promise.all(fetch).then(() => { this.requestUpdate("select_options"); + this.value = this.value; }); } diff --git a/api/js/etemplate/Et2Select/Select/Et2SelectCategory.ts b/api/js/etemplate/Et2Select/Select/Et2SelectCategory.ts index 084627bcc5..3985170142 100644 --- a/api/js/etemplate/Et2Select/Select/Et2SelectCategory.ts +++ b/api/js/etemplate/Et2Select/Select/Et2SelectCategory.ts @@ -91,6 +91,12 @@ export class Et2SelectCategory extends Et2StaticSelectMixin(Et2Select) { this._static_options = cleanSelectOptions(options); this.requestUpdate("select_options"); + + // Shoelace select has rejected our value due to missing option by now, so re-set it + this.updateComplete.then(() => + { + this.value = this.value; + }); }); } } diff --git a/api/js/etemplate/Et2Select/StaticOptions.ts b/api/js/etemplate/Et2Select/StaticOptions.ts index 99e7a6c2e8..ee772f5418 100644 --- a/api/js/etemplate/Et2Select/StaticOptions.ts +++ b/api/js/etemplate/Et2Select/StaticOptions.ts @@ -82,6 +82,12 @@ export const Et2StaticSelectMixin = > { this._static_options = new_static_options; this.requestUpdate("select_options"); + + // Shoelace select may have rejected our value due to missing option by now, so re-set it + if(this.value && this.select && this.value !== this.select.value) + { + this.value = this.value; + } } /**