Skip to content

Commit 0b44284

Browse files
committed
add empty_option example
1 parent f2d92b1 commit 0b44284

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +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 before the ones defined in `options`.', '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),
255255
('searchable', 'For select and multiple-select elements, displays them with a nice dropdown that allows searching for options.', 'BOOLEAN', FALSE, TRUE),
256256
('dropdown', 'An alias for "searchable".', 'BOOLEAN', FALSE, TRUE),
257257
('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,15 +323,18 @@ In SQLite, the query would look like
323323
```sql
324324
SELECT
325325
''select'' as type,
326+
''Select a fruit...'' as empty_option,
326327
json_group_array(json_object(
327328
''label'', name,
328329
''value'', id
329330
)) as options
330331
FROM fruits
331332
```
332333
', json('[{"component":"form", "action":"examples/show_variables.sql"},
333-
{"name": "Fruit", "type": "select", "searchable": true, "value": 1, "options":
334-
"[{\"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}]"}
335338
]')),
336339
('form', '### Multi-select
337340
You can authorize the user to select multiple options by setting the `multiple` property to `true`.

sqlpage/templates/form.handlebars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +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=""></option>{{/if~}}
78+
{{#if empty_option}}<option value="">{{empty_option}}</option>{{/if}}
7979
{{#each (parse_json options)}}
8080
<option value="{{value}}" {{#if (or (eq ../value value) selected)}}selected{{/if}}>{{label}}</option>
8181
{{/each}}

0 commit comments

Comments
 (0)