Skip to content

Commit 3bc76da

Browse files
committed
selected in multiselect options
see #147
1 parent 0467516 commit 3bc76da

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- add an `image_url` row-level attribute to the [list](https://sql.ophir.dev/documentation.sql?component=list#component) component to display small images in lists.
1414
- Fix bad contrast in links in custom page footers.
1515
- Add a new [configuration option](./configuration.md): `environment`. This allows you to set the environment in which SQLPage is running. It can be either `development` or `production`. In `production` mode, SQLPage will hide error messages and stack traces from the user, and will cache sql files in memory to avoid reloading them from disk when under heavy load.
16+
- Add support for `selected` in multi-select inputs in the [form](https://sql.ophir.dev/documentation.sql?component=form#component) component. This allows you to pre-select some options in a multi-select input.
1617

1718
## 0.17.0
1819

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
244244
('label', 'A friendly name for the text field to show to the user.', 'TEXT', FALSE, TRUE),
245245
('placeholder', 'A placeholder text that will be shown in the field when is is empty.', 'TEXT', FALSE, TRUE),
246246
('value', 'A default value that will already be present in the field when the user loads the page.', 'TEXT', FALSE, TRUE),
247-
('options', 'A json array of objects containing the label and value of all possible options of a select field. Used only when type=select.', 'JSON', FALSE, TRUE),
247+
('options', 'A json array of objects containing the label and value of all possible options of a select field. Used only when type=select. JSON objects in the array can contain the properties "label", "value" and "selected".', 'JSON', FALSE, TRUE),
248248
('required', 'Set this to true to prevent the form contents from being sent if this field is left empty by the user.', 'BOOL', FALSE, TRUE),
249249
('min', 'The minimum value to accept for an input of type number', 'NUMBER', FALSE, TRUE),
250250
('max', 'The minimum value to accept for an input of type number', 'NUMBER', FALSE, TRUE),
@@ -336,7 +336,7 @@ from json_each($preferred_fruits); -- json_each returns a table with a "value" c
336336
```
337337
', json('[{"component":"form"},
338338
{"name": "Fruit", "type": "select", "multiple": true, "description": "press ctrl to select multiple values", "options":
339-
"[{\"label\": \"Orange\", \"value\": 0}, {\"label\": \"Apple\", \"value\": 1}, {\"label\": \"Banana\", \"value\": 3}]"}
339+
"[{\"label\": \"Orange\", \"value\": 0, \"selected\": true}, {\"label\": \"Apple\", \"value\": 1}, {\"label\": \"Banana\", \"value\": 3, \"selected\": true}]"}
340340
]')),
341341
('form', 'This example illustrates the use of the `radio` type.
342342
The `name` parameter is used to group the radio buttons together.

sqlpage/templates/form.handlebars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
{{~#if multiple}} multiple {{/if~}}
6161
>
6262
{{#each (parse_json options)}}
63-
<option value="{{value}}" {{#if (eq ../value value)}}selected{{/if}}>{{label}}</option>
63+
<option value="{{value}}" {{#if (or (eq ../value value) selected)}}selected{{/if}}>{{label}}</option>
6464
{{/each}}
6565
</select>
6666
{{else}}

0 commit comments

Comments
 (0)