Skip to content

Commit d18954e

Browse files
xyllelovasoa
andauthored
add empty_option to the form component (#694)
* Update form.handlebars Add empty option to select * Update 01_documentation.sql Add documentation * Update examples/official-site/sqlpage/migrations/01_documentation.sql * Update sqlpage/templates/form.handlebars * add empty_option example * empty_option --------- Co-authored-by: Ophir LOJKINE <[email protected]>
1 parent 0026610 commit d18954e

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
- Fixed a problem where database errors would be displayed twice in the error message.
3939
- Fixed layout issues in the card component when embedding content with `embed`: remove double border and padding.
4040
- ![embedded card screenshot](https://github.com/user-attachments/assets/ea85438d-5fcb-4eed-b90b-a4385675355d)
41+
- 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.
4142

4243
## 0.30.1 (2024-10-31)
4344
- fix a bug where table sorting would break if table search was not also enabled.

examples/official-site/sqlpage/migrations/01_documentation.sql

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
251251
('max', 'The maximum value to accept for an input of type number', 'REAL', FALSE, TRUE),
252252
('checked', 'Used only for checkboxes and radio buttons. Indicates whether the checkbox should appear as already checked.', 'BOOLEAN', FALSE, TRUE),
253253
('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),
254+
('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),
254255
('searchable', 'For select and multiple-select elements, displays them with a nice dropdown that allows searching for options.', 'BOOLEAN', FALSE, TRUE),
255256
('dropdown', 'An alias for "searchable".', 'BOOLEAN', FALSE, TRUE),
256257
('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),
@@ -322,15 +323,18 @@ In SQLite, the query would look like
322323
```sql
323324
SELECT
324325
''select'' as type,
326+
''Select a fruit...'' as empty_option,
325327
json_group_array(json_object(
326328
''label'', name,
327329
''value'', id
328330
)) as options
329331
FROM fruits
330332
```
331333
', json('[{"component":"form", "action":"examples/show_variables.sql"},
332-
{"name": "Fruit", "type": "select", "searchable": true, "value": 1, "options":
333-
"[{\"label\": \"Orange\", \"value\": 0}, {\"label\": \"Apple\", \"value\": 1}, {\"label\": \"Banana\", \"value\": 3}]"}
334+
{"name": "Fruit", "type": "select",
335+
"empty_option": "Select a fruit...",
336+
"options":
337+
"[{\"label\": \"Orange\", \"value\": 0}, {\"label\": \"Apple\", \"value\": 1}, {\"label\": \"Banana\", \"value\": 3}]"}
334338
]')),
335339
('form', '### Multi-select
336340
You can authorize the user to select multiple options by setting the `multiple` property to `true`.

sqlpage/templates/form.handlebars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
{{~#if placeholder}} placeholder="{{placeholder}}" {{/if~}}
7676
{{~#if create_new}} data-create_new={{create_new}} {{/if~}}
7777
>
78+
{{#if empty_option}}<option value="">{{empty_option}}</option>{{/if}}
7879
{{#each (parse_json options)}}
7980
<option value="{{value}}" {{#if (or (eq ../value value) selected)}}selected{{/if}}>{{label}}</option>
8081
{{/each}}

0 commit comments

Comments
 (0)