From 9dc3c9050aeb42ec6e1b1b45d18fe94f7a37864d Mon Sep 17 00:00:00 2001 From: Ophir Lojkine Date: Sat, 28 Nov 2026 23:46:32 +0000 Subject: [PATCH] Move the form reference and basic examples to Markdown --- .../official-site/content/components/form.md | 254 ++++++++++++++++++ .../examples/01-submit-to-another-page.md | 25 ++ .../form/examples/02-registration.md | 29 ++ .../examples/03-input-prefix-and-suffix.md | 10 + .../components/form/examples/04-groups.md | 16 ++ .../components/form/examples/05-switch.md | 19 ++ .../sqlpage/migrations/01_documentation.sql | 156 ----------- .../migrations/82_reference_catalog.sql | 1 - .../99_shared_id_class_attributes.sql | 1 - 9 files changed, 353 insertions(+), 158 deletions(-) create mode 100644 examples/official-site/content/components/form.md create mode 100644 examples/official-site/content/components/form/examples/01-submit-to-another-page.md create mode 100644 examples/official-site/content/components/form/examples/02-registration.md create mode 100644 examples/official-site/content/components/form/examples/03-input-prefix-and-suffix.md create mode 100644 examples/official-site/content/components/form/examples/04-groups.md create mode 100644 examples/official-site/content/components/form/examples/05-switch.md diff --git a/examples/official-site/content/components/form.md b/examples/official-site/content/components/form.md new file mode 100644 index 000000000..6eb5fb97a --- /dev/null +++ b/examples/official-site/content/components/form.md @@ -0,0 +1,254 @@ +--- +icon: cursor-text +category: forms-and-feedback +summary: Collect input with text fields, file uploads, and other controls. +top: + - name: action + type: TEXT + description: An optional link to a target page that will handle the results of the form. By default the + target page is the current page with the id of the form (if passed) used as hash - this will bring us + back to the location of the form after submission. Setting it to the name of a different sql file will + load that file when the user submits the form. + - name: auto_submit + type: BOOLEAN + description: Automatically submit the form when the user changes any of its fields, and remove the validation + button. + - class + - name: enctype + type: TEXT + description: Encoding used for POST submissions. Use `multipart/form-data` for file uploads. + - name: id + type: TEXT + description: A unique identifier for the form, which can then be used to validate the form from a button + outside of the form. + - name: method + type: TEXT + description: >- + The default is `POST`: read a field named `x` as `:x` on the target page. + Use `GET` for bookmarkable searches and filters; the field appears in the URL as `?x=value` and can be read as `$x`. + - name: narrow + type: BOOLEAN + description: Whether to trim the horizontal padding between the icon and the label of the validation and + reset buttons. + - name: reset + type: TEXT + description: The text to display in the button at the bottom of the form that resets the form to its original + state. Omit this property not to show a reset button at all. + - name: reset_color + type: COLOR + description: The color of the button at the bottom of the form that resets the form to its original state. + Omit this property to use the default color. + - name: reset_icon + type: ICON + description: Name of an icon to be displayed on the left side of the reset button. + - name: reset_outline + type: COLOR + description: A color to outline the reset button. + - name: reset_shape + type: TEXT + description: The shape of the reset button (e.g., pill, square). + - name: reset_size + type: TEXT + description: The size of the reset button (e.g., sm, lg). + - name: title + type: TEXT + description: A name to display at the top of the form. It will be displayed in a larger font size at the + top of the form. + - name: validate + type: TEXT + description: The text to display in the button at the bottom of the form that submits the values. Omit + this property to let the browser display the default form validation text, or set it to the empty string + to remove the button completely. + - name: validate_color + type: COLOR + description: The color of the button at the bottom of the form that submits the values. Omit this property + to use the default color. + - name: validate_icon + type: ICON + description: Name of an icon to be displayed on the left side of the submit button. + - name: validate_outline + type: COLOR + description: A color to outline the validation button. + - name: validate_shape + type: TEXT + description: The shape of the validation button (e.g., pill, square). + - name: validate_size + type: TEXT + description: The size of the validation button (e.g., sm, lg). +row: + - name: accept + type: TEXT + description: Used only for inputs of type "file". A comma-separated list of the file types the user can + pick, given as extensions (".pdf,.png") or as MIME types ("image/*"). + - name: autocomplete + type: BOOLEAN + description: Whether the browser should suggest previously entered values for this field. + - name: autofocus + type: BOOLEAN + description: Automatically focus the field when the page is loaded + - name: checked + type: BOOLEAN + description: Used only for checkboxes and radio buttons. Indicates whether the checkbox should appear as + already checked. + - name: class + type: TEXT + description: A CSS class to apply to the form element. + - name: create_new + type: BOOLEAN + description: In a select with a dropdown (`searchable`, `dropdown` or `options_source`), this option allows + the user to enter new values, that are not in the list of options. Works for single selects and for multiselects. + - name: description + type: TEXT + description: A helper text to display near the input field. + - name: description_md + type: TEXT + description: A helper text to display near the input field - formatted using markdown. + - name: disabled + type: BOOLEAN + description: Makes the field non-editable, non-focusable, and not submitted with the form. Use readonly + instead for simple non-editable fields. + - name: dropdown + type: BOOLEAN + description: An alias for "searchable". + - name: empty_option + type: TEXT + description: 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. + - name: formaction + type: TEXT + description: When type is "submit", this specifies the URL of the file that will handle the form submission. + Useful when you need multiple submit buttons. + - name: formenctype + type: TEXT + description: |2 + + When ``type`` is ``submit`` or ``image``, this specifies how the form-data + should be encoded when submitting it to the server. + + Takes precedence over any ``enctype`` set on the ``form`` element. + + NOTE: when a ``file`` type input is present, then ``formenctype="multipart/form-data"`` + is automatically applied to the default validate button. + - name: formmethod + type: TEXT + description: When type is "submit", the HTTP method to submit the form with. Takes precedence over the + form's own "method". + - name: formnovalidate + type: BOOLEAN + description: When type is "submit", skips the browser's validation of the other fields when this button + submits the form. + - name: formtarget + type: TEXT + description: 'When type is "submit", where to display the response. Takes the same values as a link target: + "_blank" to open a new tab, "_self" to stay in the same one.' + - name: id + type: TEXT + description: A unique identifier for the input, which can then be used to select and manage the field with + Javascript code. Usefull for advanced using as setting client side event listeners, interactive control + of input field (disabled, visibility, read only, e.g.) and AJAX requests. + - name: label + type: TEXT + description: A friendly name for the text field to show to the user. + - name: list + type: TEXT + description: The id of a datalist element holding the suggestions to show for this field. The datalist + itself has to be rendered by the "html" component. + - name: max + type: REAL + description: The maximum value to accept for an input of type number + - name: maxlength + type: INTEGER + description: Maximum length of text allowed in the field. + - name: min + type: REAL + description: The minimum value to accept for an input of type number + - name: minlength + type: INTEGER + description: Minimum length of text allowed in the field. + - name: multiple + type: BOOLEAN + description: '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. For + file inputs, lets the user select several files at once: save them all with [sqlpage.persist_uploaded_files](functions.sql?function=persist_uploaded_files).' + - name: name + type: TEXT + required: true + description: The name of the input field, that you can use in the target page to get the value the user + entered for the field. + - name: options + type: JSON + description: A json array of objects containing the label and value of initial options of a select field. + Used only when type=select. JSON objects in the array can contain the properties "label", "value" and + "selected". + - name: options_source + type: URL + description: Only for inputs of type `select`. URL of a SQL file that returns JSON search results for the + dropdown. The SQL file receives the search text as `$search` and must return an array of objects with + exactly `label` and `value`. Use `options` for options that should be available before the user searches. + - name: pattern + type: TEXT + description: A regular expression that the value must match. For instance, [0-9]{3} will only accept 3 + digits. + - name: placeholder + type: TEXT + description: A placeholder text that will be shown in the field when is is empty. + - name: prefix + type: TEXT + description: Text to display on the left side of the input field, on the same line. + - name: prefix_icon + type: ICON + description: Icon to display on the left side of the input field, on the same line. + - name: readonly + type: BOOLEAN + description: Set to true to prevent the user from modifying the value of the input field. + - name: required + type: BOOLEAN + description: Set this to true to prevent the form contents from being sent if this field is left empty + by the user. + - name: rows + type: INTEGER + description: Number of rows to display for a textarea. Defaults to 3. + - name: searchable + type: BOOLEAN + description: For select and multiple-select elements, displays them with a nice dropdown that allows searching + for options. + - name: step + type: REAL + description: The increment of values in an input of type number. Set to 1 to allow only integers. + - name: suffix + type: TEXT + description: Short text to display after th input, on the same line. Useful to add units or a currency + symbol to an input. + - name: type + type: TEXT + description: 'Declares input control behavior and expected format. All HTML input types are supported (text, + number, date, file, checkbox, radio, hidden, ...). SQLPage adds some custom types: textarea, switch, + header. text by default. See https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#input_types' + - name: value + type: TEXT + description: A default value that will already be present in the field when the user loads the page. + - name: width + type: INTEGER + description: Width of the form field, between 1 and 12. +--- + +## Building forms in SQL + +The form component will display a series of input fields of various types, that can be filled in by the user. +When the user submits the form, the data is posted to an SQL file specified in the `action` property. + +### Handling submitted values + +The receiving SQL page will be able to handle the data, +and insert it into the database, use it to perform a search, format it, update existing data, etc. + +A value in a field named "x" will be available as `:x` in the SQL query of the target page. + +### Form projects + + - [A multi-step form](https://github.com/sqlpage/SQLPage/tree/main/examples/forms-with-multiple-steps), guiding the user through a process without overwhelming them with a large form. + - [File upload form](https://github.com/sqlpage/SQLPage/tree/main/examples/image%20gallery%20with%20user%20uploads), letting users upload images to a gallery. + - [Rich text editor](https://github.com/sqlpage/SQLPage/tree/main/examples/rich-text-editor), letting users write text with bold, italics, links, images, etc. + - [Master-detail form](https://github.com/sqlpage/SQLPage/tree/main/examples/master-detail-forms), to edit a list of structured items. + - [Form with a variable number of fields](https://github.com/sqlpage/SQLPage/tree/main/examples/forms%20with%20a%20variable%20number%20of%20fields), when the fields are not known in advance. + - [Demo of all input types](/examples/form), showing all the input types supported by SQLPage. diff --git a/examples/official-site/content/components/form/examples/01-submit-to-another-page.md b/examples/official-site/content/components/form/examples/01-submit-to-another-page.md new file mode 100644 index 000000000..7649a1eda --- /dev/null +++ b/examples/official-site/content/components/form/examples/01-submit-to-another-page.md @@ -0,0 +1,25 @@ +--- +rows: + - component: form + action: create_user.sql + - name: username +--- + +The best way to manage forms in SQLPage is to create at least two separate files: + + - one that will contain the form itself, and will be loaded when the user visits the page, + - one that will handle the form submission, and will redirect to whatever page you want to display after the form has been submitted. + +For instance, if you were creating a form to manage a list of users, you could create: + + - a file named `users.sql` that would contain a list of users and a form to create a new user, + - a file named `create_user.sql` that would insert the new user in the database, and then redirect to `users.sql`. + +`create_user.sql` could contain the following sql statement to [safely](safety.sql) insert the new user in the database: + +```sql +INSERT INTO users(name) VALUES(:username) +RETURNING 'redirect' AS component, 'users.sql' AS link +``` + +When loading the page, the value for `:username` will be `NULL` if no value has been submitted. diff --git a/examples/official-site/content/components/form/examples/02-registration.md b/examples/official-site/content/components/form/examples/02-registration.md new file mode 100644 index 000000000..25abab145 --- /dev/null +++ b/examples/official-site/content/components/form/examples/02-registration.md @@ -0,0 +1,29 @@ +--- +rows: + - component: form + title: User + validate: Create new user + - name: First name + placeholder: John + - name: Last name + required: true + description: We need your last name for legal purposes. + - name: Resume + type: textarea + - name: Birth date + type: date + max: '2010-01-01' + value: '1994-04-16' + - name: Password + type: password + pattern: ^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$ + required: true + description_md: '**Password Requirements:** Minimum **8 characters**, at least **one letter** & **one number**. + *Tip:* Use a passphrase for better security!' + - label: I accept the terms and conditions + name: terms + type: checkbox + required: true +--- + +A user registration form, illustrating the use of required fields, and different input types. diff --git a/examples/official-site/content/components/form/examples/03-input-prefix-and-suffix.md b/examples/official-site/content/components/form/examples/03-input-prefix-and-suffix.md new file mode 100644 index 000000000..0c020d82e --- /dev/null +++ b/examples/official-site/content/components/form/examples/03-input-prefix-and-suffix.md @@ -0,0 +1,10 @@ +--- +rows: + - component: form + - name: Your account + prefix_icon: mail + prefix: 'Email:' + suffix: '@mydomain.com' +--- + +Create prepended and appended inputs to make your forms easier to use. diff --git a/examples/official-site/content/components/form/examples/04-groups.md b/examples/official-site/content/components/form/examples/04-groups.md new file mode 100644 index 000000000..948d35edc --- /dev/null +++ b/examples/official-site/content/components/form/examples/04-groups.md @@ -0,0 +1,16 @@ +--- +rows: + - component: form + title: Information about the person + - type: header + label: Identity + - name: Name + - name: Surname + - type: header + label: Contact + - name: phone + label: Phone number + - name: Email +--- + +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. diff --git a/examples/official-site/content/components/form/examples/05-switch.md b/examples/official-site/content/components/form/examples/05-switch.md new file mode 100644 index 000000000..400e4337e --- /dev/null +++ b/examples/official-site/content/components/form/examples/05-switch.md @@ -0,0 +1,19 @@ +--- +rows: + - component: form + - type: switch + label: Dark theme + name: dark + description: Enable dark theme + - type: switch + label: A required toggle switch + name: my_checkbox + required: true + checked: true + - type: switch + label: A disabled toggle switch + name: my_field + disabled: true +--- + +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. diff --git a/examples/official-site/sqlpage/migrations/01_documentation.sql b/examples/official-site/sqlpage/migrations/01_documentation.sql index 277e5620f..19fee43d5 100644 --- a/examples/official-site/sqlpage/migrations/01_documentation.sql +++ b/examples/official-site/sqlpage/migrations/01_documentation.sql @@ -165,162 +165,6 @@ INSERT INTO example(component, description, properties) VALUES '{"title": "Final account approval", "description": "ophir.dev", "link": "https://ophir.dev/", "icon":"eye-check", "active": true},' || '{"title":"Account creation", "icon":"check"}]')); -INSERT INTO component(name, icon, description) VALUES - ('form', 'cursor-text', ' -## Building forms in SQL - -The form component will display a series of input fields of various types, that can be filled in by the user. -When the user submits the form, the data is posted to an SQL file specified in the `action` property. - -### Handling submitted values - -The receiving SQL page will be able to handle the data, -and insert it into the database, use it to perform a search, format it, update existing data, etc. - -A value in a field named "x" will be available as `:x` in the SQL query of the target page. - -### Form projects - - - [A multi-step form](https://github.com/sqlpage/SQLPage/tree/main/examples/forms-with-multiple-steps), guiding the user through a process without overwhelming them with a large form. - - [File upload form](https://github.com/sqlpage/SQLPage/tree/main/examples/image%20gallery%20with%20user%20uploads), letting users upload images to a gallery. - - [Rich text editor](https://github.com/sqlpage/SQLPage/tree/main/examples/rich-text-editor), letting users write text with bold, italics, links, images, etc. - - [Master-detail form](https://github.com/sqlpage/SQLPage/tree/main/examples/master-detail-forms), to edit a list of structured items. - - [Form with a variable number of fields](https://github.com/sqlpage/SQLPage/tree/main/examples/forms%20with%20a%20variable%20number%20of%20fields), when the fields are not known in advance. - - [Demo of all input types](/examples/form), showing all the input types supported by SQLPage. -'); -INSERT INTO parameter(component, name, description_md, type, top_level, optional) SELECT 'form', * FROM (VALUES - -- top level - ('enctype', ' -Encoding used for POST submissions. Use `multipart/form-data` for file uploads. -', 'TEXT', TRUE, TRUE), - -- item level - ('formenctype', ' -When ``type`` is ``submit`` or ``image``, this specifies how the form-data -should be encoded when submitting it to the server. - -Takes precedence over any ``enctype`` set on the ``form`` element. - -NOTE: when a ``file`` type input is present, then ``formenctype="multipart/form-data"`` -is automatically applied to the default validate button. -', 'TEXT', FALSE, TRUE) -); -INSERT INTO parameter(component, name, description, type, top_level, optional) SELECT 'form', * FROM (VALUES - -- top level - ('method', 'The default is `POST`: read a field named `x` as `:x` on the target page. Use `GET` for bookmarkable searches and filters; the field appears in the URL as `?x=value` and can be read as `$x`.', 'TEXT', TRUE, TRUE), - ('action', 'An optional link to a target page that will handle the results of the form. By default the target page is the current page with the id of the form (if passed) used as hash - this will bring us back to the location of the form after submission. Setting it to the name of a different sql file will load that file when the user submits the form.', 'TEXT', TRUE, TRUE), - ('title', 'A name to display at the top of the form. It will be displayed in a larger font size at the top of the form.', 'TEXT', TRUE, TRUE), - ('validate', 'The text to display in the button at the bottom of the form that submits the values. Omit this property to let the browser display the default form validation text, or set it to the empty string to remove the button completely.', 'TEXT', TRUE, TRUE), - ('validate_color', 'The color of the button at the bottom of the form that submits the values. Omit this property to use the default color.', 'COLOR', TRUE, TRUE), - ('validate_outline', 'A color to outline the validation button.', 'COLOR', TRUE, TRUE), - ('validate_shape', 'The shape of the validation button (e.g., pill, square).', 'TEXT', TRUE, TRUE), - ('validate_size', 'The size of the validation button (e.g., sm, lg).', 'TEXT', TRUE, TRUE), - ('reset', 'The text to display in the button at the bottom of the form that resets the form to its original state. Omit this property not to show a reset button at all.', 'TEXT', TRUE, TRUE), - ('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), - ('auto_submit', 'Automatically submit the form when the user changes any of its fields, and remove the validation button.', 'BOOLEAN', TRUE, TRUE), - ('validate_icon', 'Name of an icon to be displayed on the left side of the submit button.', 'ICON', TRUE, TRUE), - ('reset_icon', 'Name of an icon to be displayed on the left side of the reset button.', 'ICON', TRUE, TRUE), - ('reset_color', 'The color of the button at the bottom of the form that resets the form to its original state. Omit this property to use the default color.', 'COLOR', TRUE, TRUE), - ('reset_outline', 'A color to outline the reset button.', 'COLOR', TRUE, TRUE), - ('reset_shape', 'The shape of the reset button (e.g., pill, square).', 'TEXT', TRUE, TRUE), - ('reset_size', 'The size of the reset button (e.g., sm, lg).', 'TEXT', TRUE, TRUE), - ('narrow', 'Whether to trim the horizontal padding between the icon and the label of the validation and reset buttons.', 'BOOLEAN', TRUE, TRUE), - -- item level - ('type', 'Declares input control behavior and expected format. All HTML input types are supported (text, number, date, file, checkbox, radio, hidden, ...). SQLPage adds some custom types: textarea, switch, header. text by default. See https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#input_types', 'TEXT', FALSE, TRUE), - ('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), - ('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 initial 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), - ('options_source', 'Only for inputs of type `select`. URL of a SQL file that returns JSON search results for the dropdown. The SQL file receives the search text as `$search` and must return an array of objects with exactly `label` and `value`. Use `options` for options that should be available before the user searches.', 'URL', FALSE, TRUE), - ('required', 'Set this to true to prevent the form contents from being sent if this field is left empty by the user.', 'BOOLEAN', FALSE, TRUE), - ('min', 'The minimum value to accept for an input of type number', 'REAL', FALSE, TRUE), - ('max', 'The maximum value to accept for an input of type number', 'REAL', FALSE, TRUE), - ('checked', 'Used only for checkboxes and radio buttons. Indicates whether the checkbox should appear as already checked.', 'BOOLEAN', FALSE, TRUE), - ('multiple', '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. For file inputs, lets the user select several files at once: save them all with [sqlpage.persist_uploaded_files](functions.sql?function=persist_uploaded_files).', 'BOOLEAN', FALSE, TRUE), - ('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), - ('searchable', 'For select and multiple-select elements, displays them with a nice dropdown that allows searching for options.', 'BOOLEAN', FALSE, TRUE), - ('dropdown', 'An alias for "searchable".', 'BOOLEAN', FALSE, TRUE), - ('create_new', 'In a select with a dropdown (`searchable`, `dropdown` or `options_source`), this option allows the user to enter new values, that are not in the list of options. Works for single selects and for multiselects.', 'BOOLEAN', FALSE, TRUE), - ('step', 'The increment of values in an input of type number. Set to 1 to allow only integers.', 'REAL', FALSE, TRUE), - ('description', 'A helper text to display near the input field.', 'TEXT', FALSE, TRUE), - ('description_md', 'A helper text to display near the input field - formatted using markdown.', 'TEXT', FALSE, TRUE), - ('pattern', 'A regular expression that the value must match. For instance, [0-9]{3} will only accept 3 digits.', 'TEXT', FALSE, TRUE), - ('autofocus', 'Automatically focus the field when the page is loaded', 'BOOLEAN', FALSE, TRUE), - ('width', 'Width of the form field, between 1 and 12.', 'INTEGER', FALSE, TRUE), - ('autocomplete', 'Whether the browser should suggest previously entered values for this field.', 'BOOLEAN', FALSE, TRUE), - ('minlength', 'Minimum length of text allowed in the field.', 'INTEGER', FALSE, TRUE), - ('maxlength', 'Maximum length of text allowed in the field.', 'INTEGER', FALSE, TRUE), - ('formaction', 'When type is "submit", this specifies the URL of the file that will handle the form submission. Useful when you need multiple submit buttons.', 'TEXT', FALSE, TRUE), - ('formmethod', 'When type is "submit", the HTTP method to submit the form with. Takes precedence over the form''s own "method".', 'TEXT', FALSE, TRUE), - ('formnovalidate', 'When type is "submit", skips the browser''s validation of the other fields when this button submits the form.', 'BOOLEAN', FALSE, TRUE), - ('formtarget', 'When type is "submit", where to display the response. Takes the same values as a link target: "_blank" to open a new tab, "_self" to stay in the same one.', 'TEXT', FALSE, TRUE), - ('accept', 'Used only for inputs of type "file". A comma-separated list of the file types the user can pick, given as extensions (".pdf,.png") or as MIME types ("image/*").', 'TEXT', FALSE, TRUE), - ('list', 'The id of a datalist element holding the suggestions to show for this field. The datalist itself has to be rendered by the "html" component.', 'TEXT', FALSE, TRUE), - ('class', 'A CSS class to apply to the form element.', 'TEXT', FALSE, TRUE), - ('prefix_icon','Icon to display on the left side of the input field, on the same line.','ICON',FALSE,TRUE), - ('prefix','Text to display on the left side of the input field, on the same line.','TEXT',FALSE,TRUE), - ('suffix','Short text to display after th input, on the same line. Useful to add units or a currency symbol to an input.','TEXT',FALSE,TRUE), - ('readonly','Set to true to prevent the user from modifying the value of the input field.','BOOLEAN',FALSE,TRUE), - ('rows','Number of rows to display for a textarea. Defaults to 3.','INTEGER',FALSE,TRUE), - ('disabled','Makes the field non-editable, non-focusable, and not submitted with the form. Use readonly instead for simple non-editable fields.','BOOLEAN',FALSE,TRUE), - ('id','A unique identifier for the input, which can then be used to select and manage the field with Javascript code. Usefull for advanced using as setting client side event listeners, interactive control of input field (disabled, visibility, read only, e.g.) and AJAX requests.','TEXT',FALSE,TRUE) -) x; -INSERT INTO example(component, description, properties) VALUES - ( - 'form', - ' - -The best way to manage forms in SQLPage is to create at least two separate files: - - - one that will contain the form itself, and will be loaded when the user visits the page, - - one that will handle the form submission, and will redirect to whatever page you want to display after the form has been submitted. - -For instance, if you were creating a form to manage a list of users, you could create: - - - a file named `users.sql` that would contain a list of users and a form to create a new user, - - a file named `create_user.sql` that would insert the new user in the database, and then redirect to `users.sql`. - -`create_user.sql` could contain the following sql statement to [safely](safety.sql) insert the new user in the database: - -```sql -INSERT INTO users(name) VALUES(:username) -RETURNING ''redirect'' AS component, ''users.sql'' AS link -``` - -When loading the page, the value for `:username` will be `NULL` if no value has been submitted. -', - json('[{"component":"form", "action": "create_user.sql"}, {"name": "username"}]')), - ('form', 'A user registration form, illustrating the use of required fields, and different input types.', - json('[{"component":"form", "title": "User", "validate": "Create new user"}, '|| - '{"name": "First name", "placeholder": "John"}, '|| - '{"name": "Last name", "required": true, "description": "We need your last name for legal purposes."},'|| - '{"name": "Resume", "type": "textarea"},'|| - '{"name": "Birth date", "type": "date", "max": "2010-01-01", "value": "1994-04-16"},'|| - '{"name": "Password", "type": "password", "pattern": "^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{8,}$", "required": true, "description_md": "**Password Requirements:** Minimum **8 characters**, at least **one letter** & **one number**. *Tip:* Use a passphrase for better security!"},'|| - '{"label": "I accept the terms and conditions", "name": "terms", "type": "checkbox", "required": true}'|| - ']')), - ('form','Create prepended and appended inputs to make your forms easier to use.', - json('[{"component":"form"}, '|| - '{"name": "Your account", "prefix_icon": "mail", "prefix": "Email:", "suffix": "@mydomain.com"}, ' || - ']')), - - ('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.', - json('[{"component":"form","title":"Information about the person"}, '|| - '{"type": "header", "label": "Identity"},' || - '{"name": "Name"},' || - '{"name": "Surname"},' || - '{"type": "header","label": "Contact"},' || - '{"name": "phone", "label": "Phone number"},' || - '{"name": "Email"},' || - ']')), - - ('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.', - json('[{"component":"form"}, - {"type": "switch", "label": "Dark theme", "name": "dark", "description": "Enable dark theme"}, - {"type": "switch", "label": "A required toggle switch", "name": "my_checkbox", "required": true,"checked": true}, - {"type": "switch", "label": "A disabled toggle switch", "name": "my_field", "disabled": true} - ]')); - INSERT INTO component(name, icon, description) VALUES ('chart', 'timeline', 'A component that plots data. Line, area, bar, and pie charts are all supported. Each item in the component is a data point in the graph.'); diff --git a/examples/official-site/sqlpage/migrations/82_reference_catalog.sql b/examples/official-site/sqlpage/migrations/82_reference_catalog.sql index 6da77a1cf..1c1faf91a 100644 --- a/examples/official-site/sqlpage/migrations/82_reference_catalog.sql +++ b/examples/official-site/sqlpage/migrations/82_reference_catalog.sql @@ -38,7 +38,6 @@ WITH copy(name, category, summary) AS (VALUES ('tracking', 'display-data', 'Show a sequence of activity or status changes as colored segments.'), ('button', 'forms-and-feedback', 'Follow a link, download a file, or submit a form.'), - ('form', 'forms-and-feedback', 'Collect input with text fields, file uploads, and other controls.'), ('login', 'forms-and-feedback', 'Display a sign-in form for a username and password.'), ('modal', 'forms-and-feedback', 'Open a dialog over the page for details, forms, or media.'), diff --git a/examples/official-site/sqlpage/migrations/99_shared_id_class_attributes.sql b/examples/official-site/sqlpage/migrations/99_shared_id_class_attributes.sql index d6a1f33c3..7a1f613a0 100644 --- a/examples/official-site/sqlpage/migrations/99_shared_id_class_attributes.sql +++ b/examples/official-site/sqlpage/migrations/99_shared_id_class_attributes.sql @@ -59,7 +59,6 @@ FROM (VALUES ('csv', TRUE), ('datagrid', TRUE), ('divider', TRUE), - ('form', TRUE), ('list', TRUE), ('list', FALSE), ('map', TRUE),