Skip to content

Commit 29f6447

Browse files
form improvements with new types of field: header and switch (#906)
* form improvements with new types of field: header and switch * added checked toggle switch example * add names to the switch checkboxes * update form header margins * trailing whitespace * docs --------- Co-authored-by: lovasoa <[email protected]>
1 parent bbaf209 commit 29f6447

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Updated sqlparser to [v0.56](https://github.com/apache/datafusion-sqlparser-rs/blob/main/changelog/0.56.0.md), with many improvements including:
1919
- Add support for the xmltable(...) function in postgres
2020
- Add support for MSSQL IF/ELSE statements.
21+
- Add support for nice "switch" checkboxes in the form component using `'switch' as type`
22+
- Add support for headers in the form component using
2123

2224
## v0.34 (2025-03-23)
2325

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
276276
('id', 'A unique identifier for the form, which can then be used to validate the form from a button outside of the form.', 'TEXT', TRUE, TRUE),
277277
('auto_submit', 'Automatically submit the form when the user changes any of its fields, and remove the validation button.', 'BOOLEAN', TRUE, TRUE),
278278
-- item level
279-
('type', 'The type of input to use: text for a simple text field, textarea for a multi-line text input control, number to accept only numbers, checkbox or radio for a button that is part of a group specified in the ''name'' parameter, hidden for a value that will be submitted but not shown to the user. text by default.', 'TEXT', FALSE, TRUE),
279+
('type', 'The type of input to use: text for a simple text field, textarea for a multi-line text input control, number to accept only numbers, checkbox, switch, or radio for a button that is part of a group specified in the ''name'' parameter, header for a form header, hidden for a value that will be submitted but not shown to the user. text by default.', 'TEXT', FALSE, TRUE),
280280
('name', 'The name of the input field, that you can use in the target page to get the value the user entered for the field.', 'TEXT', FALSE, FALSE),
281281
('label', 'A friendly name for the text field to show to the user.', 'TEXT', FALSE, TRUE),
282282
('placeholder', 'A placeholder text that will be shown in the field when is is empty.', 'TEXT', FALSE, TRUE),
@@ -347,6 +347,24 @@ When loading the page, the value for `:username` will be `NULL` if no value has
347347
json('[{"component":"form"}, '||
348348
'{"name": "Your account", "prefix_icon": "mail", "prefix": "Email:", "suffix": "@mydomain.com"}, ' ||
349349
']')),
350+
351+
('form','With the header type, you can group your input fields based on a theme. For example, you can categorize fields according to a person''s identity and their contact information.',
352+
json('[{"component":"form","title":"Information about the person"}, '||
353+
'{"type": "header", "label": "Identity"},' ||
354+
'{"name": "Name"},' ||
355+
'{"name": "Surname"},' ||
356+
'{"type": "header","label": "Contact"},' ||
357+
'{"name": "phone", "label": "Phone number"},' ||
358+
'{"name": "Email"},' ||
359+
']')),
360+
361+
('form','A toggle switch in an HTML form is a user interface element that allows users to switch between two states, typically "on" and "off." It visually resembles a physical switch and is often used for settings or options that can be enabled or disabled.',
362+
json('[{"component":"form"},
363+
{"type": "switch", "label": "Dark theme", "name": "dark", "description": "Enable dark theme"},
364+
{"type": "switch", "label": "A required toggle switch", "name": "my_checkbox", "required": true,"checked": true},
365+
{"type": "switch", "label": "A disabled toggle switch", "name": "my_field", "disabled": true}
366+
]')),
367+
350368
('form', 'This example illustrates the use of the `select` type.
351369
In this select input, the various options are hardcoded, but they could also be loaded from a database table,
352370
[using a function to convert the rows into a json array](/blog.sql?post=JSON%20in%20SQL%3A%20A%20Comprehensive%20Guide) like

sqlpage/templates/form.handlebars

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
{{/if}}
1616
<div class="row">
1717
{{#each_row}}
18+
{{#if (eq type "header")}}
19+
<h3 class="text-center mt-2 mb-1"{{#if id}} id="{{id}}"{{/if}}>{{label}}</h3>
20+
{{else}}
1821
{{#if (or (eq type "radio") (eq type "checkbox"))}}
1922
<div class="form-selectgroup form-selectgroup-boxes d-flex flex-column mx-0 my-1 col-md-{{default width 12}}">
2023
<label class="form-selectgroup-item flex-fill mx-0">
@@ -39,6 +42,25 @@
3942
</label>
4043
</div>
4144
{{else}}
45+
{{~#if (eq type "switch")}}
46+
<div class="form-selectgroup form-selectgroup-boxes d-flex flex-column mx-0 my-1 col-md-{{default width 12}}">
47+
<label class="form-check form-switch">
48+
<input class="form-check-input" type="checkbox" {{#if id}}id="{{id}}" {{/if}}name="{{name}}" value="{{value}}"{{#if required}} required{{/if}}{{#if checked}} checked{{/if}}{{#if disabled}} disabled{{/if~}}/>
49+
<span class="form-check-label">
50+
{{default label value}}
51+
{{~#if required}}
52+
<span class="text-danger ms-1" aria-label="required" title="required">*</span>
53+
{{/if}}
54+
{{#if description}}
55+
<small class="form-hint mt-0">{{description}}</small>
56+
{{/if}}
57+
{{#if description_md}}
58+
<small class="form-hint mt-0">{{{markdown description_md}}}</small>
59+
{{/if}}
60+
</span>
61+
</label>
62+
</div>
63+
{{else}}
4264
{{~#if (eq type "hidden")}}
4365
<input type="hidden" name="{{name}}" {{#if id}}id="{{id}}" {{/if}}value="{{value}}">
4466
{{else}}
@@ -132,6 +154,8 @@
132154
</label>
133155
{{~/if~}}
134156
{{/if}}
157+
{{/if}}
158+
{{/if}}
135159
{{#if (eq type "file")}}
136160
<!-- Change the form encoding type if this is a file input-->
137161
{{#delay}}formenctype="multipart/form-data"{{/delay}}

0 commit comments

Comments
 (0)