docs: Mentioned validateOnLoad prop for Form component (#223)

* docs: Mentioned validateOnLoad prop

* refactor: Changed some class name for better readability
This commit is contained in:
Lalit 2022-12-02 19:48:17 +05:30 committed by GitHub
parent 29c8c870b7
commit 7e4c05a2c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 18 deletions

View file

@ -11,10 +11,10 @@ The `Form` component renders a form element and various control components (e.g.
```astro ```astro
--- ---
import Form, { FormGroup } from "@astro-reactive/form"; import Form, { FormGroup } from "@astro-reactive/form";
const form = new FormGroup( const form = new FormGroup();
// your controls configuration data // your controls configuration data
);
--- ---
<Form formGroups={form} /> <Form formGroups={form} />
``` ```
@ -24,12 +24,11 @@ const form = new FormGroup(
npm i @astro-reactive/form npm i @astro-reactive/form
``` ```
## Usage ## Usage
Setting up the `Form` component is mainly done by providing it your configuration via the `formGroups` property which takes either a `FormGroup` or an array `FormGroup[]`. Setting up the `Form` component is mainly done by providing it your configuration via the `formGroups` property which takes either a `FormGroup` or an array `FormGroup[]`.
*See the documentation for the [FormGroup](/en/api/form/form-group) class.* _See the documentation for the [FormGroup](/en/api/form/form-group) class._
### Setting up a form ### Setting up a form
@ -49,7 +48,7 @@ const form = new FormGroup([
name: "comment", name: "comment",
label: "Feedback", label: "Feedback",
type: "textarea", type: "textarea",
value: "Nice!" value: "Nice!",
}, },
{ {
name: "size", name: "size",
@ -60,6 +59,7 @@ const form = new FormGroup([
}, },
]); ]);
--- ---
<Form formGroups={form} /> <Form formGroups={form} />
``` ```
@ -71,7 +71,6 @@ The `FormGroup` constructor takes an array `ControlConfig[]`.
> **📝 Note:** The `ControlConfig` type will be defined in the [FormControl](/en/api/form/form-control) class documentation. > **📝 Note:** The `ControlConfig` type will be defined in the [FormControl](/en/api/form/form-control) class documentation.
### Setting up multiple field sets ### Setting up multiple field sets
To render a form with multiple field sets, assign an array `FormGroup[]` to the `formGroups` property. To render a form with multiple field sets, assign an array `FormGroup[]` to the `formGroups` property.
@ -122,6 +121,7 @@ const skills = new FormGroup(
"Skills" "Skills"
); );
--- ---
<Form formGroups={[nameForm, skills]} /> <Form formGroups={[nameForm, skills]} />
``` ```
@ -148,45 +148,58 @@ const submitControl: Submit = {
type: "submit", type: "submit",
}; };
--- ---
<Form formGroups={form} submitControl={submitControl} /> <Form formGroups={form} submitControl={submitControl} />
``` ```
This is a very crude solution to prevent having multiple submit buttons. For suggestions to improve this, join our [discussions](https://github.com/ayoayco/astro-reactive-library/discussions). This is a very crude solution to prevent having multiple submit buttons. For suggestions to improve this, join our [discussions](https://github.com/ayoayco/astro-reactive-library/discussions).
----- ---
## Properties ## Properties
The following are input properties a `Form` component can take. The following are input properties a `Form` component can take.
| Property | Type | | | Property | Type | |
|---|---|---| | ------------------------------------------- | -------------------------- | -------- |
| [formGroups](#formgroups) | `FormGroup \| FormGroup[]` | required | | [formGroups](#formgroups) | `FormGroup \| FormGroup[]` | required |
| [readOnly](#readonly) | `boolean` | optional | | [readOnly](#readonly) | `boolean` | optional |
| [showValidationHints](#showvalidationhints) | `boolean` | optional | | [showValidationHints](#showvalidationhints) | `boolean` | optional |
| [validateOnLoad](#validateOnLoad) | `boolean` | optional |
| [submitControl](#submitcontrol) | `Submit` | optional | | [submitControl](#submitcontrol) | `Submit` | optional |
| [theme](#theme) | `'light' \| 'dark'` | optional | | [theme](#theme) | `'light' \| 'dark'` | optional |
### `formGroups` ### `formGroups`
Type: `FormGroup | FormGroup[]` Type: `FormGroup | FormGroup[]`
Determines how the form is are rendered Determines how the form is are rendered
### `readOnly` ### `readOnly`
Type: `boolean` Type: `boolean`
Sets the whole form as read-only. Sets the whole form as read-only.
### `showValidationHints` ### `showValidationHints`
Type: `boolean` Type: `boolean`
When used with our `validator` package, the `Form` component is able to render validation hints when `showValidationHints` is set to true: When used with our `validator` package, the `Form` component is able to render validation hints when `showValidationHints` is set to true:
- asterisks on required controls' labels - asterisks on required controls' labels
- controls with validation errors are colored red - controls with validation errors are colored red
### `validateOnLoad`
Type: `boolean`
When used with our `validator` package, the `Form` component is able to render validation errors on server-side rendering when `validateOnLoad` is set to true otherwise, the validation errors will only be rendered on the client-side.
### `submitControl` ### `submitControl`
Type: `Submit` Type: `Submit`
### `theme` ### `theme`
Type: `'light' | 'dark'` Type: `'light' | 'dark'`

View file

@ -27,7 +27,7 @@ import { Icon } from "astro-icon";
<button <button
type="button" type="button"
class="ml-auto -mx-1.5 -my-1.5 bg-white text-gray-400 hover:text-gray-900 rounded-lg focus:ring-2 focus:ring-gray-300 p-1.5 hover:bg-gray-100 inline-flex h-8 w-8 dark:text-gray-500 dark:hover:text-white dark:bg-gray-800 dark:hover:bg-gray-700" class="ml-auto -mx-1.5 -my-1.5 bg-white text-gray-400 hover:text-gray-900 rounded-lg focus:ring-2 focus:ring-gray-300 p-1.5 hover:bg-gray-100 inline-flex h-8 w-8 dark:text-gray-500 dark:hover:text-white dark:bg-gray-800 dark:hover:bg-gray-700"
id="toast-close" id="toast-close-btn"
aria-label="Close" aria-label="Close"
> >
<span class="sr-only">Close</span> <span class="sr-only">Close</span>
@ -92,7 +92,7 @@ import { Icon } from "astro-icon";
const copyCommandButton = document.getElementById("copy-command-button"); const copyCommandButton = document.getElementById("copy-command-button");
const commandText = document.getElementById("command").innerText; const commandText = document.getElementById("command").innerText;
const toastSuccess = document.getElementById("toast-success"); const toastSuccess = document.getElementById("toast-success");
const toastClose = document.getElementById("toast-close"); const toastClose = document.getElementById("toast-close-btn");
copyCommandButton?.addEventListener("click", () => { copyCommandButton?.addEventListener("click", () => {
toastSuccess.style.transform = "translateX(-50%) translateY(0)"; toastSuccess.style.transform = "translateX(-50%) translateY(0)";