Skip to content

Commit

Permalink
selected in multiselect options
Browse files Browse the repository at this point in the history
see #147
  • Loading branch information
lovasoa committed Dec 6, 2023
1 parent 0467516 commit 3bc76da
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- 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.
- Fix bad contrast in links in custom page footers.
- 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.
- 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.

## 0.17.0

Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
('label', 'A friendly name for the text field to show to the user.', 'TEXT', FALSE, TRUE),
('placeholder', 'A placeholder text that will be shown in the field when is is empty.', 'TEXT', FALSE, TRUE),
('value', 'A default value that will already be present in the field when the user loads the page.', 'TEXT', FALSE, TRUE),
('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),
('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),
('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),
('min', 'The minimum value to accept for an input of type number', 'NUMBER', FALSE, TRUE),
('max', 'The minimum value to accept for an input of type number', 'NUMBER', FALSE, TRUE),
Expand Down Expand Up @@ -336,7 +336,7 @@ from json_each($preferred_fruits); -- json_each returns a table with a "value" c
```
', json('[{"component":"form"},
{"name": "Fruit", "type": "select", "multiple": true, "description": "press ctrl to select multiple values", "options":
"[{\"label\": \"Orange\", \"value\": 0}, {\"label\": \"Apple\", \"value\": 1}, {\"label\": \"Banana\", \"value\": 3}]"}
"[{\"label\": \"Orange\", \"value\": 0, \"selected\": true}, {\"label\": \"Apple\", \"value\": 1}, {\"label\": \"Banana\", \"value\": 3, \"selected\": true}]"}
]')),
('form', 'This example illustrates the use of the `radio` type.
The `name` parameter is used to group the radio buttons together.
Expand Down
2 changes: 1 addition & 1 deletion sqlpage/templates/form.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
{{~#if multiple}} multiple {{/if~}}
>
{{#each (parse_json options)}}
<option value="{{value}}" {{#if (eq ../value value)}}selected{{/if}}>{{label}}</option>
<option value="{{value}}" {{#if (or (eq ../value value) selected)}}selected{{/if}}>{{label}}</option>
{{/each}}
</select>
{{else}}
Expand Down

0 comments on commit 3bc76da

Please sign in to comment.