From 6e6d891543488eadecf43e75be01207227a5e2c5 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Mon, 8 Jun 2026 17:32:10 +0200 Subject: [PATCH 1/3] pat-select2: Remove invalid comment. --- src/pat/select2/select2.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pat/select2/select2.js b/src/pat/select2/select2.js index c7581723e..f9f059b50 100644 --- a/src/pat/select2/select2.js +++ b/src/pat/select2/select2.js @@ -217,7 +217,6 @@ export default Base.extend({ this.options.multiple === undefined ? true : this.options.multiple; this.options.ajax = this.options.ajax || {}; this.options.ajax.url = this.options.vocabularyUrl; - // XXX removing the following function does'nt break tests. dead code? this.options.initSelection = ($el, callback) => { const data = []; const value = $el.val(); From 063bc094285aad0385c74d01d1323a0da10c92b5 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Mon, 8 Jun 2026 02:11:14 +0200 Subject: [PATCH 2/3] fix(pat-select2): Show predefined value for single-select widgets. Single-select widgets did not show their predefined value. This is now fixed. --- src/pat/select2/select2.js | 10 +++++++++- src/pat/select2/select2.test.js | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/pat/select2/select2.js b/src/pat/select2/select2.js index f9f059b50..3518ff60c 100644 --- a/src/pat/select2/select2.js +++ b/src/pat/select2/select2.js @@ -221,10 +221,18 @@ export default Base.extend({ const data = []; const value = $el.val(); for (const val of value.split(this.options.separator)) { + if (val === "") { + // Skip empty values, e.g. from an empty input. + continue; + } const _val = utils.removeHTML(val); data.push({ id: _val, text: _val }); } - callback(data); + // Select2 v3 expects a single object for single-select + // widgets and an array for multi-select widgets. Passing an + // array to a single select leaves `data.text` undefined and + // the pre-set value is not rendered. + callback(this.options.multiple ? data : data[0] || null); }; } diff --git a/src/pat/select2/select2.test.js b/src/pat/select2/select2.test.js index 7fd4cb70c..fa3c573a0 100644 --- a/src/pat/select2/select2.test.js +++ b/src/pat/select2/select2.test.js @@ -100,6 +100,29 @@ describe("Select2", function () { expect(select2.options.ajax.url).toEqual("select2-users-vocabulary"); }); + it("renders the preset value of a single-select input widget", async function () { + document.body.innerHTML = ` + + `; + + registry.scan(document.body); + await utils.timeout(1); + + const el = document.querySelector("input.pat-select2"); + expect($(el).select2("data")).toEqual({ + id: "Europe/Vienna", + text: "Europe/Vienna", + }); + expect($(el).parent().find(".select2-chosen").text()).toEqual("Europe/Vienna"); + }); + it("displays the vocabulary when clicking an empty checkbox", async function () { document.body.innerHTML = ` Date: Mon, 8 Jun 2026 17:35:21 +0200 Subject: [PATCH 3/3] maint(pat-select2): Add test for predefined value for a select widget. --- src/pat/select2/select2.test.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/pat/select2/select2.test.js b/src/pat/select2/select2.test.js index fa3c573a0..6301c5248 100644 --- a/src/pat/select2/select2.test.js +++ b/src/pat/select2/select2.test.js @@ -123,6 +123,27 @@ describe("Select2", function () { expect($(el).parent().find(".select2-chosen").text()).toEqual("Europe/Vienna"); }); + it("renders the preset value of a single-select select widget", async function () { + document.body.innerHTML = ` + + `; + + registry.scan(document.body); + await utils.timeout(1); + + const el = document.querySelector("select.pat-select2"); + // For a native