From 2e9b87403abd46371a15c5bf4ea3a18b818a8f66 Mon Sep 17 00:00:00 2001
From: mkerz-masfg <151519264+mkerz-masfg@users.noreply.github.com>
Date: Mon, 30 Nov 2026 10:51:19 +0100
Subject: [PATCH 1/6] Render the create row and the no-results text of
searchable selects
Pass render.option_create and render.no_results to Tom Select, with the texts from data-create_new_text and data no_results_text and the current English texts as default. The create row also gets role="option" and an id:
Tom Select gives both only to regular options, so screen readers did not announce the create row when it was the active option.
---
frontend/src/tomselect.ts | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/frontend/src/tomselect.ts b/frontend/src/tomselect.ts
index fc97a66e3..37e252aa7 100644
--- a/frontend/src/tomselect.ts
+++ b/frontend/src/tomselect.ts
@@ -16,6 +16,8 @@ function sqlpage_select_dropdown(root: InitRoot) {
}
}
+let create_option_count = 0;
+
function sqlpage_select_dropdown_individual(s: HTMLSelectElement) {
s.removeAttribute("data-pre-init");
// See: https://github.com/orchidjs/tom-select/issues/716
@@ -23,6 +25,14 @@ function sqlpage_select_dropdown_individual(s: HTMLSelectElement) {
// This is a workaround to fix that
const is_focused = s === document.activeElement;
+ const create_text = s.dataset.create_new_text ?? "Add";
+ const no_results_text = s.dataset.no_results_text ?? "No results found";
+ // Tom Select gives role="option" and an id only to regular options. Without
+ // them, screen readers do not announce the row that creates a new value when
+ // it is the active option, because aria-activedescendant has nothing to name.
+ create_option_count += 1;
+ const create_id = `${s.id || "sqlpage-select"}-create-${create_option_count}`;
+
const tom = new TomSelect(s, {
load: sqlpage_load_options_source(s.dataset.options_source),
valueField: "value",
@@ -32,6 +42,15 @@ function sqlpage_select_dropdown_individual(s: HTMLSelectElement) {
maxOptions: null,
closeAfterSelect: !s.multiple,
clearAfterSelect: true,
+ render: {
+ option_create: (
+ data: { input: string },
+ html: (text: string) => string,
+ ) =>
+ `
`,
+ },
});
if (is_focused) tom.focus();
s.form?.addEventListener("reset", async () => {
From 3b45fd40f7979181ceae7c54e38fc4b451dfa074 Mon Sep 17 00:00:00 2001
From: mkerz-masfg <151519264+mkerz-masfg@users.noreply.github.com>
Date: Mon, 30 Nov 2026 10:53:22 +0100
Subject: [PATCH 2/6] Pass create_new_text and no_results_text to the select
dropdown
---
sqlpage/templates/form.handlebars | 2 ++
1 file changed, 2 insertions(+)
diff --git a/sqlpage/templates/form.handlebars b/sqlpage/templates/form.handlebars
index 22b02ddd6..7011f2ada 100644
--- a/sqlpage/templates/form.handlebars
+++ b/sqlpage/templates/form.handlebars
@@ -103,6 +103,8 @@
{{~#if options_source}} data-options_source="{{options_source}}" {{/if~}}
{{~#if placeholder}} placeholder="{{placeholder}}" {{/if~}}
{{~#if create_new}} data-create_new={{create_new}} {{/if~}}
+ {{~#if create_new_text}} data-create_new_text="{{create_new_text}}" {{/if~}}
+ {{~#if no_results_text}} data-no_results_text="{{no_results_text}}" {{/if~}}
>
{{#if empty_option}}{{/if}}
{{#each (parse_json options)}}
From 42a81209416f4ffcd1f1d78484a2d63b9ee99f0a Mon Sep 17 00:00:00 2001
From: mkerz-masfg <151519264+mkerz-masfg@users.noreply.github.com>
Date: Mon, 30 Nov 2026 10:54:26 +0100
Subject: [PATCH 3/6] Document create_new_text and no_results_text
---
examples/official-site/sqlpage/migrations/01_documentation.sql | 2 ++
1 file changed, 2 insertions(+)
diff --git a/examples/official-site/sqlpage/migrations/01_documentation.sql b/examples/official-site/sqlpage/migrations/01_documentation.sql
index d82b0214e..9063fa289 100644
--- a/examples/official-site/sqlpage/migrations/01_documentation.sql
+++ b/examples/official-site/sqlpage/migrations/01_documentation.sql
@@ -317,6 +317,8 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
('searchable', 'For select and multiple-select elements, displays them with a nice dropdown that allows searching for options.', 'BOOLEAN', FALSE, TRUE),
('dropdown', 'An alias for "searchable".', 'BOOLEAN', FALSE, TRUE),
('create_new', 'In a select with a dropdown (`searchable`, `dropdown` or `options_source`), this option allows the user to enter new values, that are not in the list of options. Works for single selects and for multiselects.', 'BOOLEAN', FALSE, TRUE),
+ ('create_new_text', 'Text shown before the typed value in the dropdown row that creates a new value, when `create_new` is set. Replaces the default "Add", for instance to translate it.', 'TEXT', FALSE, TRUE),
+ ('no_results_text', 'Text shown in a select with a dropdown when the search matches no option. Replaces the default "No results found", for instance to translate it.', 'TEXT', FALSE, TRUE),
('step', 'The increment of values in an input of type number. Set to 1 to allow only integers.', 'REAL', FALSE, TRUE),
('description', 'A helper text to display near the input field.', 'TEXT', FALSE, TRUE),
('description_md', 'A helper text to display near the input field - formatted using markdown.', 'TEXT', FALSE, TRUE),
From e111d58b35b588c90d1800a74fdc9011fcfd1c7f Mon Sep 17 00:00:00 2001
From: mkerz-masfg <151519264+mkerz-masfg@users.noreply.github.com>
Date: Mon, 30 Nov 2026 10:55:07 +0100
Subject: [PATCH 4/6] Add changelog entry for the select dropdown texts
---
CHANGELOG.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 06959dff1..67191b615 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
## unreleased
+- New `create_new_text` and `no_results_text` properties on `select` fields translate the dropdown texts "Add …" and "No results found". The row that creates a new value is now announced by screen readers when it is the active option. ([#1699](https://github.com/sqlpage/SQLPage/issues/1699))
- The `table` component can fetch and display HTML fragments in selected columns using `embed`.
- New `navbar_toggle_label` property on the `shell` and `close_label` property on the `alert` component, to translate the accessible names of the menu toggle button and of the alert close button. ([#1632](https://github.com/sqlpage/SQLPage/issues/1632))
- Updated Rust and browser dependencies, including SQLite, ApexCharts, and Tabler.
From cba65f558ad65cdf042663c41334ef994030b056 Mon Sep 17 00:00:00 2001
From: mkerz-masfg <151519264+mkerz-masfg@users.noreply.github.com>
Date: Mon, 30 Nov 2026 10:55:58 +0100
Subject: [PATCH 5/6] Add select dropdown texts fixture page
---
tests/end-to-end/fixtures/select-create-text/index.sql | 6 ++++++
1 file changed, 6 insertions(+)
create mode 100644 tests/end-to-end/fixtures/select-create-text/index.sql
diff --git a/tests/end-to-end/fixtures/select-create-text/index.sql b/tests/end-to-end/fixtures/select-create-text/index.sql
new file mode 100644
index 000000000..e807b68d7
--- /dev/null
+++ b/tests/end-to-end/fixtures/select-create-text/index.sql
@@ -0,0 +1,6 @@
+SELECT 'form' AS component;
+SELECT 'translated' AS name, 'select' AS type, 1 AS searchable, 1 AS create_new,
+ 'Neu anlegen:' AS create_new_text, 'Keine Treffer' AS no_results_text,
+ '[{"label": "Red", "value": "red"}, {"label": "Blue", "value": "blue"}]' AS options;
+SELECT 'default' AS name, 'select' AS type, 1 AS searchable, 1 AS create_new,
+ '[{"label": "Red", "value": "red"}, {"label": "Blue", "value": "blue"}]' AS options;
From ade1851f902e162e6abb80dd928e297eaefa00cd Mon Sep 17 00:00:00 2001
From: mkerz-masfg <151519264+mkerz-masfg@users.noreply.github.com>
Date: Mon, 30 Nov 2026 10:56:35 +0100
Subject: [PATCH 6/6] Test the dropdown texts and the active create row
---
.../fixtures/select-create-text/test.ts | 32 +++++++++++++++++++
1 file changed, 32 insertions(+)
create mode 100644 tests/end-to-end/fixtures/select-create-text/test.ts
diff --git a/tests/end-to-end/fixtures/select-create-text/test.ts b/tests/end-to-end/fixtures/select-create-text/test.ts
new file mode 100644
index 000000000..b8566b16a
--- /dev/null
+++ b/tests/end-to-end/fixtures/select-create-text/test.ts
@@ -0,0 +1,32 @@
+import { expect, type Page, test } from "../../fixture.ts";
+
+async function search(page: Page, name: string, text: string) {
+ const field = page
+ .locator("label")
+ .filter({ has: page.locator(`select[name="${name}"]`) });
+ const input = field.locator('input[role="combobox"]');
+ await field.locator(".ts-control").click();
+ await input.fill(text);
+ return { input, dropdown: field.getByRole("listbox") };
+}
+
+test("translated texts, and the create row is the active option", async ({
+ page,
+}) => {
+ const { input, dropdown } = await search(page, "translated", "Gruen");
+ const create = dropdown.getByRole("option", { name: "Neu anlegen: Gruen…" });
+ await expect(create).toBeVisible();
+ await expect(input).toHaveAttribute(
+ "aria-activedescendant",
+ (await create.getAttribute("id")) ?? "",
+ );
+ await expect(dropdown.getByText("Keine Treffer")).toBeVisible();
+});
+
+test("without the properties, the texts stay the same", async ({ page }) => {
+ const { dropdown } = await search(page, "default", "Gruen");
+ await expect(
+ dropdown.getByRole("option", { name: "Add Gruen…" }),
+ ).toBeVisible();
+ await expect(dropdown.getByText("No results found")).toBeVisible();
+});