From 8f058b932a43aa3e74b02b487cdb951324b6402a Mon Sep 17 00:00:00 2001 From: Xylle Date: Sat, 16 Nov 2024 12:06:45 +0100 Subject: [PATCH 1/6] Update form.handlebars Add empty option to select --- sqlpage/templates/form.handlebars | 1 + 1 file changed, 1 insertion(+) diff --git a/sqlpage/templates/form.handlebars b/sqlpage/templates/form.handlebars index d37bc2a9..2be7ca37 100644 --- a/sqlpage/templates/form.handlebars +++ b/sqlpage/templates/form.handlebars @@ -75,6 +75,7 @@ {{~#if placeholder}} placeholder="{{placeholder}}" {{/if~}} {{~#if create_new}} data-create_new={{create_new}} {{/if~}} > + {{~#if emptyoption}}{{/if~}} {{#each (parse_json options)}} {{/each}} From eec428bb29d47747e5d43289aee731f984172695 Mon Sep 17 00:00:00 2001 From: Xylle Date: Sat, 16 Nov 2024 19:58:56 +0100 Subject: [PATCH 2/6] Update 01_documentation.sql Add documentation --- examples/official-site/sqlpage/migrations/01_documentation.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/official-site/sqlpage/migrations/01_documentation.sql b/examples/official-site/sqlpage/migrations/01_documentation.sql index 481fa5e7..9c4fbf37 100644 --- a/examples/official-site/sqlpage/migrations/01_documentation.sql +++ b/examples/official-site/sqlpage/migrations/01_documentation.sql @@ -251,6 +251,7 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S ('max', 'The maximum value to accept for an input of type number', 'REAL', FALSE, TRUE), ('checked', 'Used only for checkboxes and radio buttons. Indicates whether the checkbox should appear as already checked.', 'BOOLEAN', FALSE, TRUE), ('multiple', 'Used only for select elements. Indicates that multiple elements can be selected simultaneously. When using multiple, you should add square brackets after the variable name: ''my_variable[]'' as name', 'BOOLEAN', FALSE, TRUE), + ('emptyoption', 'Used only for select elements. Add empty option at first', 'BOOLEAN', FALSE, TRUE), ('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 multiselect with a dropdown, this option allows the user to enter new values, that are not in the list of options.', 'BOOLEAN', FALSE, TRUE), From a104c7d3c9efb9d8859c7d6ee75596c917bf2512 Mon Sep 17 00:00:00 2001 From: Ophir LOJKINE Date: Sun, 17 Nov 2024 10:43:44 +0100 Subject: [PATCH 3/6] Update examples/official-site/sqlpage/migrations/01_documentation.sql --- examples/official-site/sqlpage/migrations/01_documentation.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/official-site/sqlpage/migrations/01_documentation.sql b/examples/official-site/sqlpage/migrations/01_documentation.sql index 9c4fbf37..4f458a7e 100644 --- a/examples/official-site/sqlpage/migrations/01_documentation.sql +++ b/examples/official-site/sqlpage/migrations/01_documentation.sql @@ -251,7 +251,7 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S ('max', 'The maximum value to accept for an input of type number', 'REAL', FALSE, TRUE), ('checked', 'Used only for checkboxes and radio buttons. Indicates whether the checkbox should appear as already checked.', 'BOOLEAN', FALSE, TRUE), ('multiple', 'Used only for select elements. Indicates that multiple elements can be selected simultaneously. When using multiple, you should add square brackets after the variable name: ''my_variable[]'' as name', 'BOOLEAN', FALSE, TRUE), - ('emptyoption', 'Used only for select elements. Add empty option at first', 'BOOLEAN', FALSE, TRUE), + ('empty_option', 'Only for inputs of type `select`. Adds an empty option before the ones defined in `options`.', 'BOOLEAN', FALSE, TRUE), ('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 multiselect with a dropdown, this option allows the user to enter new values, that are not in the list of options.', 'BOOLEAN', FALSE, TRUE), From f2d92b186cb21b421323db98d36cc5a4773bb7d7 Mon Sep 17 00:00:00 2001 From: Ophir LOJKINE Date: Sun, 17 Nov 2024 10:43:52 +0100 Subject: [PATCH 4/6] Update sqlpage/templates/form.handlebars --- sqlpage/templates/form.handlebars | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlpage/templates/form.handlebars b/sqlpage/templates/form.handlebars index 2be7ca37..4c23ba42 100644 --- a/sqlpage/templates/form.handlebars +++ b/sqlpage/templates/form.handlebars @@ -75,7 +75,7 @@ {{~#if placeholder}} placeholder="{{placeholder}}" {{/if~}} {{~#if create_new}} data-create_new={{create_new}} {{/if~}} > - {{~#if emptyoption}}{{/if~}} + {{~#if empty_option}}{{/if~}} {{#each (parse_json options)}} {{/each}} From 0b4428404089b4b3850da568c6ef27a3b17a2965 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Sun, 17 Nov 2024 11:03:31 +0100 Subject: [PATCH 5/6] add empty_option example --- .../sqlpage/migrations/01_documentation.sql | 9 ++++++--- sqlpage/templates/form.handlebars | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/official-site/sqlpage/migrations/01_documentation.sql b/examples/official-site/sqlpage/migrations/01_documentation.sql index 4f458a7e..aa21da28 100644 --- a/examples/official-site/sqlpage/migrations/01_documentation.sql +++ b/examples/official-site/sqlpage/migrations/01_documentation.sql @@ -251,7 +251,7 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S ('max', 'The maximum value to accept for an input of type number', 'REAL', FALSE, TRUE), ('checked', 'Used only for checkboxes and radio buttons. Indicates whether the checkbox should appear as already checked.', 'BOOLEAN', FALSE, TRUE), ('multiple', 'Used only for select elements. Indicates that multiple elements can be selected simultaneously. When using multiple, you should add square brackets after the variable name: ''my_variable[]'' as name', 'BOOLEAN', FALSE, TRUE), - ('empty_option', 'Only for inputs of type `select`. Adds an empty option before the ones defined in `options`.', 'BOOLEAN', FALSE, TRUE), + ('empty_option', 'Only for inputs of type `select`. Adds an empty option with the given label before the ones defined in `options`. Useful when generating other options from a database table.', 'TEXT', FALSE, TRUE), ('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 multiselect with a dropdown, this option allows the user to enter new values, that are not in the list of options.', 'BOOLEAN', FALSE, TRUE), @@ -323,6 +323,7 @@ In SQLite, the query would look like ```sql SELECT ''select'' as type, + ''Select a fruit...'' as empty_option, json_group_array(json_object( ''label'', name, ''value'', id @@ -330,8 +331,10 @@ SELECT FROM fruits ``` ', json('[{"component":"form", "action":"examples/show_variables.sql"}, - {"name": "Fruit", "type": "select", "searchable": true, "value": 1, "options": - "[{\"label\": \"Orange\", \"value\": 0}, {\"label\": \"Apple\", \"value\": 1}, {\"label\": \"Banana\", \"value\": 3}]"} + {"name": "Fruit", "type": "select", + "empty_option": "Select a fruit...", + "options": + "[{\"label\": \"Orange\", \"value\": 0}, {\"label\": \"Apple\", \"value\": 1}, {\"label\": \"Banana\", \"value\": 3}]"} ]')), ('form', '### Multi-select You can authorize the user to select multiple options by setting the `multiple` property to `true`. diff --git a/sqlpage/templates/form.handlebars b/sqlpage/templates/form.handlebars index 4c23ba42..84aaa633 100644 --- a/sqlpage/templates/form.handlebars +++ b/sqlpage/templates/form.handlebars @@ -75,7 +75,7 @@ {{~#if placeholder}} placeholder="{{placeholder}}" {{/if~}} {{~#if create_new}} data-create_new={{create_new}} {{/if~}} > - {{~#if empty_option}}{{/if~}} + {{#if empty_option}}{{/if}} {{#each (parse_json options)}} {{/each}} From a91b849fc5a0e52a20ab0c49e1988d4c40a9beb1 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Sun, 17 Nov 2024 11:13:03 +0100 Subject: [PATCH 6/6] empty_option --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1505dd14..0dbb8b32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ - Fixed a problem where database errors would be displayed twice in the error message. - Fixed layout issues in the card component when embedding content with `embed`: remove double border and padding. - ![embedded card screenshot](https://github.com/user-attachments/assets/ea85438d-5fcb-4eed-b90b-a4385675355d) +- Added support for `empty_option` in the form component to add an empty option before the options defined in `options`. Useful when generating other options from a database table. ## 0.30.1 (2024-10-31) - fix a bug where table sorting would break if table search was not also enabled.