@iress-oss/ids-mcp-server 5.14.2 → 5.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/generated/docs/components_components-alert-docs.md +492 -0
- package/generated/docs/components_components-autocomplete-docs.md +3485 -0
- package/generated/docs/{components-autocomplete-recipes-docs.md → components_components-autocomplete-recipes-docs.md} +32 -14
- package/generated/docs/{components-badge-docs.md → components_components-badge-docs.md} +222 -30
- package/generated/docs/components_components-button-docs.md +2078 -0
- package/generated/docs/components_components-button-recipes-docs.md +37 -0
- package/generated/docs/components_components-buttongroup-docs.md +1045 -0
- package/generated/docs/components_components-card-docs.md +2276 -0
- package/generated/docs/{components-card-recipes-docs.md → components_components-card-recipes-docs.md} +131 -14
- package/generated/docs/components_components-checkbox-docs.md +1054 -0
- package/generated/docs/{components-checkboxgroup-docs.md → components_components-checkboxgroup-docs.md} +1000 -81
- package/generated/docs/{components-checkboxgroup-recipes-docs.md → components_components-checkboxgroup-recipes-docs.md} +101 -11
- package/generated/docs/{components-col-docs.md → components_components-col-docs.md} +331 -58
- package/generated/docs/components_components-combobox-docs.md +3767 -0
- package/generated/docs/{components-container-docs.md → components_components-container-docs.md} +61 -24
- package/generated/docs/{components-divider-docs.md → components_components-divider-docs.md} +83 -24
- package/generated/docs/{components-expander-docs.md → components_components-expander-docs.md} +264 -33
- package/generated/docs/{components-field-docs.md → components_components-field-docs.md} +814 -120
- package/generated/docs/components_components-filter-docs.md +4080 -0
- package/generated/docs/{components-form-docs.md → components_components-form-docs.md} +1488 -358
- package/generated/docs/{components-form-recipes-docs.md → components_components-form-recipes-docs.md} +174 -64
- package/generated/docs/components_components-hide-docs.md +293 -0
- package/generated/docs/components_components-icon-docs.md +1337 -0
- package/generated/docs/{components-inline-docs.md → components_components-inline-docs.md} +462 -42
- package/generated/docs/components_components-input-docs.md +1468 -0
- package/generated/docs/components_components-input-recipes-docs.md +367 -0
- package/generated/docs/components_components-inputcurrency-docs.md +432 -0
- package/generated/docs/{components-inputcurrency-recipes-docs.md → components_components-inputcurrency-recipes-docs.md} +110 -17
- package/generated/docs/components_components-label-docs.md +323 -0
- package/generated/docs/components_components-menu-docs.md +2345 -0
- package/generated/docs/components_components-menu-menuitem-docs.md +633 -0
- package/generated/docs/{components-modal-docs.md → components_components-modal-docs.md} +1625 -232
- package/generated/docs/components_components-navbar-docs.md +1847 -0
- package/generated/docs/{components-navbar-recipes-docs.md → components_components-navbar-recipes-docs.md} +697 -39
- package/generated/docs/{components-panel-docs.md → components_components-panel-docs.md} +754 -57
- package/generated/docs/components_components-placeholder-docs.md +92 -0
- package/generated/docs/components_components-popover-docs.md +1641 -0
- package/generated/docs/{components-popover-recipes-docs.md → components_components-popover-recipes-docs.md} +347 -17
- package/generated/docs/components_components-progress-docs.md +115 -0
- package/generated/docs/components_components-provider-docs.md +114 -0
- package/generated/docs/components_components-radio-docs.md +491 -0
- package/generated/docs/{components-radiogroup-docs.md → components_components-radiogroup-docs.md} +943 -75
- package/generated/docs/components_components-readonly-docs.md +263 -0
- package/generated/docs/components_components-richselect-docs.md +6497 -0
- package/generated/docs/{components-row-docs.md → components_components-row-docs.md} +353 -43
- package/generated/docs/{components-select-docs.md → components_components-select-docs.md} +719 -61
- package/generated/docs/components_components-skeleton-docs.md +480 -0
- package/generated/docs/{components-skeleton-recipes-docs.md → components_components-skeleton-recipes-docs.md} +50 -10
- package/generated/docs/{components-skiplink-docs.md → components_components-skiplink-docs.md} +53 -14
- package/generated/docs/components_components-slideout-docs.md +2262 -0
- package/generated/docs/components_components-slider-docs.md +1276 -0
- package/generated/docs/components_components-spinner-docs.md +82 -0
- package/generated/docs/{components-stack-docs.md → components_components-stack-docs.md} +223 -40
- package/generated/docs/components_components-table-docs.md +3651 -0
- package/generated/docs/components_components-tabset-docs.md +772 -0
- package/generated/docs/components_components-tabset-tab-docs.md +262 -0
- package/generated/docs/components_components-tag-docs.md +259 -0
- package/generated/docs/{components-text-docs.md → components_components-text-docs.md} +491 -51
- package/generated/docs/{components-toaster-docs.md → components_components-toaster-docs.md} +224 -71
- package/generated/docs/components_components-toaster-toast-docs.md +634 -0
- package/generated/docs/components_components-toggle-docs.md +461 -0
- package/generated/docs/{components-tooltip-docs.md → components_components-tooltip-docs.md} +286 -41
- package/generated/docs/{components-validationmessage-docs.md → components_components-validationmessage-docs.md} +230 -61
- package/generated/docs/components_contact-us-docs.md +12 -0
- package/generated/docs/{foundations-accessibility-docs.md → components_foundations-accessibility-docs.md} +11 -21
- package/generated/docs/{foundations-colours-docs.md → components_foundations-colour-030-colours.md} +8 -15
- package/generated/docs/{foundations-consistency-docs.md → components_foundations-consistency-docs.md} +12 -20
- package/generated/docs/{foundations-content-docs.md → components_foundations-content-docs.md} +6 -11
- package/generated/docs/components_foundations-introduction-docs.md +15 -0
- package/generated/docs/{foundations-principles-docs.md → components_foundations-principles-docs.md} +14 -24
- package/generated/docs/components_foundations-typography-docs.md +608 -0
- package/generated/docs/{foundations-user-experience-docs.md → components_foundations-user-experience-docs.md} +16 -26
- package/generated/docs/{foundations-visual-design-docs.md → components_foundations-visual-design-docs.md} +10 -17
- package/generated/docs/{frequently-asked-questions-docs.md → components_frequently-asked-questions-docs.md} +14 -23
- package/generated/docs/components_get-started-develop-docs.md +84 -0
- package/generated/docs/components_get-started-using-storybook-docs.md +55 -0
- package/generated/docs/components_introduction-docs.md +15 -0
- package/generated/docs/{patterns-loading-docs.md → components_patterns-loading-docs.md} +711 -143
- package/generated/docs/components_resources-changelog-docs.md +4 -0
- package/generated/docs/{resources-code-katas-docs.md → components_resources-code-katas-docs.md} +5 -9
- package/generated/docs/{resources-migration-guides-from-v4-to-v5-docs.md → components_resources-migration-guides-from-v4-to-v5-docs.md} +54 -239
- package/generated/docs/{versions-docs.md → components_versions-docs.md} +5 -8
- package/generated/docs/guidelines.md +484 -200
- package/generated/docs/introduction-docs.md +19 -30
- package/package.json +41 -45
- package/generated/docs/components-alert-docs.md +0 -130
- package/generated/docs/components-autocomplete-docs.md +0 -754
- package/generated/docs/components-button-docs.md +0 -362
- package/generated/docs/components-button-recipes-docs.md +0 -76
- package/generated/docs/components-buttongroup-docs.md +0 -310
- package/generated/docs/components-card-docs.md +0 -494
- package/generated/docs/components-checkbox-docs.md +0 -193
- package/generated/docs/components-combobox-docs.md +0 -1016
- package/generated/docs/components-filter-docs.md +0 -1109
- package/generated/docs/components-hide-docs.md +0 -265
- package/generated/docs/components-icon-docs.md +0 -553
- package/generated/docs/components-input-docs.md +0 -335
- package/generated/docs/components-input-recipes-docs.md +0 -140
- package/generated/docs/components-inputcurrency-docs.md +0 -157
- package/generated/docs/components-label-docs.md +0 -135
- package/generated/docs/components-menu-docs.md +0 -704
- package/generated/docs/components-menu-menuitem-docs.md +0 -193
- package/generated/docs/components-navbar-docs.md +0 -291
- package/generated/docs/components-placeholder-docs.md +0 -27
- package/generated/docs/components-popover-docs.md +0 -464
- package/generated/docs/components-progress-docs.md +0 -104
- package/generated/docs/components-radio-docs.md +0 -107
- package/generated/docs/components-readonly-docs.md +0 -89
- package/generated/docs/components-richselect-docs.md +0 -2433
- package/generated/docs/components-skeleton-docs.md +0 -214
- package/generated/docs/components-slideout-docs.md +0 -538
- package/generated/docs/components-slider-docs.md +0 -346
- package/generated/docs/components-spinner-docs.md +0 -59
- package/generated/docs/components-table-ag-grid-docs.md +0 -2666
- package/generated/docs/components-table-docs.md +0 -1305
- package/generated/docs/components-tabset-docs.md +0 -341
- package/generated/docs/components-tabset-tab-docs.md +0 -86
- package/generated/docs/components-tag-docs.md +0 -115
- package/generated/docs/components-toaster-toast-docs.md +0 -157
- package/generated/docs/components-toggle-docs.md +0 -158
- package/generated/docs/contact-us-docs.md +0 -27
- package/generated/docs/extensions-editor-docs.md +0 -288
- package/generated/docs/extensions-editor-recipes-docs.md +0 -39
- package/generated/docs/foundations-introduction-docs.md +0 -17
- package/generated/docs/foundations-typography-docs.md +0 -191
- package/generated/docs/get-started-develop-docs.md +0 -48
- package/generated/docs/get-started-using-storybook-docs.md +0 -68
- package/generated/docs/resources-changelog-docs.md +0 -6
- package/generated/docs/themes-available-themes-docs.md +0 -66
- package/generated/docs/themes-introduction-docs.md +0 -121
- package/generated/docs/themes-tokens-docs.md +0 -1200
- /package/{LICENSE.txt → LICENSE} +0 -0
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
Form
|
|
2
|
+
====
|
|
3
3
|
|
|
4
4
|
Overview
|
|
5
5
|
--------
|
|
6
6
|
|
|
7
7
|
Use the `IressForm` component when you want to request, validate and process data from the user.
|
|
8
8
|
|
|
9
|
+
[](./iframe.html?id=components-form--simple)
|
|
10
|
+
|
|
9
11
|
\*Required Name
|
|
10
12
|
|
|
11
13
|
\*Required Email address
|
|
12
14
|
|
|
13
15
|
Sign up
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
\[data-radix-scroll-area-viewport\] { scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; } \[data-radix-scroll-area-viewport\]::-webkit-scrollbar { display: none; } :where(\[data-radix-scroll-area-viewport\]) { display: flex; flex-direction: column; align-items: stretch; } :where(\[data-radix-scroll-area-content\]) { flex-grow: 1; }
|
|
17
|
+
```
|
|
18
18
|
|
|
19
|
-
<
|
|
19
|
+
<ForwardedForm\>
|
|
20
20
|
<IressStack gutter\="md"\>
|
|
21
21
|
<IressFormField
|
|
22
22
|
label\="Name"
|
|
@@ -44,16 +44,49 @@ Hide code
|
|
|
44
44
|
\>
|
|
45
45
|
Sign up </IressButton\>
|
|
46
46
|
</IressStack\>
|
|
47
|
-
</
|
|
47
|
+
</ForwardedForm\>
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Props
|
|
52
|
+
-----
|
|
53
|
+
|
|
54
|
+
Below are the custom props you can access when using `IressForm`, which includes the props for the [`useForm` hook from React Hook Forms](https://react-hook-form.com/docs/useform). In addition to these, you have access to the original props of the underlying [`form` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form).
|
|
55
|
+
|
|
56
|
+
| Name | Description | Default | Control |
|
|
57
|
+
| --- | --- | --- | --- |
|
|
58
|
+
| alert |
|
|
59
|
+
\-
|
|
60
|
+
|
|
61
|
+
| \- | Choose option...nonebasicAlert |
|
|
62
|
+
| children |
|
|
63
|
+
|
|
64
|
+
object
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
| \- | Choose option...nonesimplesupportedControlsreadOnly |
|
|
69
|
+
| form |
|
|
70
|
+
|
|
71
|
+
React hook form instance from `useForm`, use if you need more control over the internal state.
|
|
72
|
+
|
|
73
|
+
const form = useForm();
|
|
74
|
+
return <IressForm form={form} />;
|
|
75
|
+
|
|
48
76
|
|
|
49
|
-
|
|
77
|
+
UseFormReturn
|
|
50
78
|
|
|
51
|
-
|
|
52
|
-
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
| \- | Set object |
|
|
82
|
+
| Show React Hook Forms itemsReact Hook Forms | Show React Hook Forms items |
|
|
83
|
+
|
|
84
|
+
Key concepts
|
|
85
|
+
------------
|
|
53
86
|
|
|
54
87
|
As of version 5, `IressForm` is built on top of [React Hook Forms](https://react-hook-form.com/). This provides you the power of React Hook Forms with the convenience of IDS form components. However, there are some key differences to be aware of as it may affect how you build your forms.
|
|
55
88
|
|
|
56
|
-
###
|
|
89
|
+
### State management
|
|
57
90
|
|
|
58
91
|
`IressForm` manages the state of the form, including the form data and validation. This is done using the `useForm` hook from React Hook Forms. This hook provides a way to manage the form state, and provides methods to interact with the form. This was done to simplify the form components, make them more predictable (as the form becomes the single source of truth for all form related data) and improve performance by reducing re-renders (very important for large forms).
|
|
59
92
|
|
|
@@ -64,13 +97,15 @@ Due to this change, there are a few things you should consider during developmen
|
|
|
64
97
|
|
|
65
98
|
See below an example comparing a version 4 and version 5 `IressForm` when managing form state.
|
|
66
99
|
|
|
67
|
-
|
|
100
|
+
Diff
|
|
101
|
+
|
|
102
|
+
Old
|
|
68
103
|
|
|
69
|
-
|
|
104
|
+
New
|
|
70
105
|
|
|
71
106
|
<table class="css-1n5o7vh-diff-container"><tbody><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text">import { IressForm, IressField, IressInput, IressCheckboxGroup, IressCheckbox } from '@iress/components';</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text">import { IressForm, IressFormField, IressInput, IressCheckboxGroup, IressCheckbox } from '@iress-oss/ids-components';</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-10regm7-empty-line"><pre></pre></td><td class="css-vl0irh-content css-10regm7-empty-line"><pre class="css-o1u8iu-content-text"></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-10regm7-empty-line"><pre></pre></td><td class="css-vl0irh-content css-10regm7-empty-line"><pre class="css-o1u8iu-content-text"></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text">export const App = () => {</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text">const ConditionalFields = () => {</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> // We need to create our own state to manage the visibility of the fields, </pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> // Instead of creating our own state, we can now use the form state via the useWatch hook, </pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> // which means we have two sources of truth potentially making our code harder to maintain</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> // meaning we still have a single source of truth</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> const [show, setShow] = useState(['name']);</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> const show = IressForm.useWatch({ name: 'show'});</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-10regm7-empty-line"><pre></pre></td><td class="css-vl0irh-content css-10regm7-empty-line"><pre class="css-o1u8iu-content-text"></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker"><pre></pre></td><td class="css-vl0irh-content"><pre class="css-o1u8iu-content-text"> return (</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> <IressForm></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> <></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> <IressField label="Show fields"></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> <IressFormField </pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> <IressCheckboxGroup value={show} onChange={(newValues) => setShow(newValues)}></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> label="Show fields" </pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> name="show"</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> render={(controlledProps) => (</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> <IressCheckboxGroup {...controlledProps}></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker"><pre></pre></td><td class="css-vl0irh-content"><pre class="css-o1u8iu-content-text"> <IressCheckbox value="name">Name</IressCheckbox></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker"><pre></pre></td><td class="css-vl0irh-content"><pre class="css-o1u8iu-content-text"> <IressCheckbox value="email">Email</IressCheckbox></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker"><pre></pre></td><td class="css-vl0irh-content"><pre class="css-o1u8iu-content-text"> </IressCheckboxGroup></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> </IressField></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> )}</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> {show.includes('name') && (</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> /></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> <IressField label="Name"></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> {show?.includes('name') && (</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> <IressInput name="name" /></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> <IressFormField </pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> </IressField></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> label="Name" </pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> )}</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> name="name"</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> {show.includes('email') && (</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> render={(controlledProps) => <IressInput {...controlledProps} />}</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> <IressField label="Email"></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> /></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> <IressInput name="email" type="email" /></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> )}</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> </IressField></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> {show?.includes('email') && (</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> )}</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> <IressFormField </pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> </IressForm></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> label="Email" </pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> name="email"</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> render={(controlledProps) => <IressInput {...controlledProps} type="email" />}</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> /></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> )}</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> </></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker"><pre></pre></td><td class="css-vl0irh-content"><pre class="css-o1u8iu-content-text"> );</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker"><pre></pre></td><td class="css-vl0irh-content"><pre class="css-o1u8iu-content-text">};</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-10regm7-empty-line css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-10regm7-empty-line css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text">export const App = () => (</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> <IressForm defaultValues={{ show: ['name'] }}></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> <ConditionalFields /> </pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> </IressForm></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text">);</pre></td></tr></tbody></table>
|
|
72
107
|
|
|
73
|
-
###
|
|
108
|
+
### Validation
|
|
74
109
|
|
|
75
110
|
Validation is now done declaratively using the `rules` prop on the `IressFormField` component. This is based on the [rules available in React Hook Forms](https://www.react-hook-form.com/api/useform/register/#options). This change was made to allow for more complex validation rules to be implemented.
|
|
76
111
|
|
|
@@ -82,13 +117,15 @@ Due to this change, there are a few things you should consider during developmen
|
|
|
82
117
|
|
|
83
118
|
See below an example comparing a version 4 and version 5 `IressForm` when adding validation rules.
|
|
84
119
|
|
|
85
|
-
|
|
120
|
+
Diff
|
|
86
121
|
|
|
87
|
-
|
|
122
|
+
Old
|
|
123
|
+
|
|
124
|
+
New
|
|
88
125
|
|
|
89
126
|
<table class="css-1n5o7vh-diff-container"><tbody><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text">import { IressForm, IressField, IressInput, IressButton } from '@iress/components';</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text">import { IressForm, IressFormField, IressInput, IressButton } from '@iress-oss/ids-components';</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-10regm7-empty-line"><pre></pre></td><td class="css-vl0irh-content css-10regm7-empty-line"><pre class="css-o1u8iu-content-text"></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker"><pre></pre></td><td class="css-vl0irh-content"><pre class="css-o1u8iu-content-text">export const App = () => (</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> <IressForm valueMissing="{{fieldName}} needs to be filled in!"></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> <IressForm></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> <IressField label="Name"></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> <IressFormField </pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> <IressInput name="name" required /></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> label="Name"</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> </IressField></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> name="name"</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> <IressField label="Email"></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> render={(controlledProps) => <IressInput {...controlledProps} />}</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> <IressInput name="email" maxLength={10} /></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> rules={{ required: 'Name needs to be filled in!' }}</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-rq9a2a-diff-removed"><pre>-</pre></td><td class="css-vl0irh-content css-rq9a2a-diff-removed"><pre class="css-o1u8iu-content-text"> </IressField></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> /></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> <IressFormField </pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> label="Email"</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> name="email"</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> render={(controlledProps) => <IressInput {...controlledProps} type="email" maxLength={10} />}</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> rules={{ maxLength: 10 }}</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker css-cnnxkz-diff-added"><pre>+</pre></td><td class="css-vl0irh-content css-cnnxkz-diff-added"><pre class="css-o1u8iu-content-text"> /></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker"><pre></pre></td><td class="css-vl0irh-content"><pre class="css-o1u8iu-content-text"> <IressButton type="submit" mode="primary"></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker"><pre></pre></td><td class="css-vl0irh-content"><pre class="css-o1u8iu-content-text"> Sign up</pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker"><pre></pre></td><td class="css-vl0irh-content"><pre class="css-o1u8iu-content-text"> </IressButton></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker"><pre></pre></td><td class="css-vl0irh-content"><pre class="css-o1u8iu-content-text"> </IressForm></pre></td></tr><tr class="css-1n7ec1i-line"><td class="css-17vezug-marker"><pre></pre></td><td class="css-vl0irh-content"><pre class="css-o1u8iu-content-text">);</pre></td></tr></tbody></table>
|
|
90
127
|
|
|
91
|
-
###
|
|
128
|
+
### Syncing state
|
|
92
129
|
|
|
93
130
|
For most scenarios, you should use the `onSubmit` event to sync the form data with other state management systems (eg. server, browser storage or state management libraries such as Redux). This event is emitted when the form passes validation, and contains a map of the field names and the data entered by the user.
|
|
94
131
|
|
|
@@ -99,23 +136,6 @@ Consider the following for your development:
|
|
|
99
136
|
* Only use other state management systems to fill out the form at the initial render using `defaultValues`. After that, use the `onSubmit` event to sync the form data with your state.
|
|
100
137
|
* If you need to set form with data coming from an external system, use the `ref` of the form to `reset` the form values.
|
|
101
138
|
|
|
102
|
-
\[data-radix-scroll-area-viewport\] {
|
|
103
|
-
scrollbar-width: none;
|
|
104
|
-
-ms-overflow-style: none;
|
|
105
|
-
-webkit-overflow-scrolling: touch;
|
|
106
|
-
}
|
|
107
|
-
\[data-radix-scroll-area-viewport\]::-webkit-scrollbar {
|
|
108
|
-
display: none;
|
|
109
|
-
}
|
|
110
|
-
:where(\[data-radix-scroll-area-viewport\]) {
|
|
111
|
-
display: flex;
|
|
112
|
-
flex-direction: column;
|
|
113
|
-
align-items: stretch;
|
|
114
|
-
}
|
|
115
|
-
:where(\[data-radix-scroll-area-content\]) {
|
|
116
|
-
flex-grow: 1;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
139
|
const ref \= useRef<FormRef | null\>(null);
|
|
120
140
|
const api \= useApi();
|
|
121
141
|
const handleSubmit \= async (data) \=> {
|
|
@@ -129,12 +149,12 @@ return (
|
|
|
129
149
|
... </IressForm\>
|
|
130
150
|
);
|
|
131
151
|
|
|
132
|
-
|
|
152
|
+
```
|
|
133
153
|
|
|
134
|
-
|
|
135
|
-
|
|
154
|
+
Usage
|
|
155
|
+
-----
|
|
136
156
|
|
|
137
|
-
###
|
|
157
|
+
### Fields
|
|
138
158
|
|
|
139
159
|
Use the `IressFormField` component to create form fields. This component is a layout component that wraps around form controls such as `IressInput`. It provides a consistent layout for form fields, and hooks into the `IressForm` component to provide validation and error handling.
|
|
140
160
|
|
|
@@ -144,35 +164,20 @@ It has three required props:
|
|
|
144
164
|
* `label`: The label for the field.
|
|
145
165
|
* `render`: A render prop that renders the form control. It is passed an object containing the props to be spread onto the form control to allow it to be controlled by the form.
|
|
146
166
|
|
|
147
|
-
\[data-radix-scroll-area-viewport\] {
|
|
148
|
-
scrollbar-width: none;
|
|
149
|
-
-ms-overflow-style: none;
|
|
150
|
-
-webkit-overflow-scrolling: touch;
|
|
151
|
-
}
|
|
152
|
-
\[data-radix-scroll-area-viewport\]::-webkit-scrollbar {
|
|
153
|
-
display: none;
|
|
154
|
-
}
|
|
155
|
-
:where(\[data-radix-scroll-area-viewport\]) {
|
|
156
|
-
display: flex;
|
|
157
|
-
flex-direction: column;
|
|
158
|
-
align-items: stretch;
|
|
159
|
-
}
|
|
160
|
-
:where(\[data-radix-scroll-area-content\]) {
|
|
161
|
-
flex-grow: 1;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
167
|
<IressFormField
|
|
165
168
|
name\="email"
|
|
166
169
|
label\="Email"
|
|
167
170
|
render\={(controlledProps) \=> <IressInput {...controlledProps} type\="email" />}
|
|
168
171
|
/>
|
|
169
172
|
|
|
170
|
-
|
|
173
|
+
```
|
|
171
174
|
|
|
172
|
-
####
|
|
175
|
+
#### Supported form controls
|
|
173
176
|
|
|
174
177
|
Here are some examples of how to use `IressFormField` with different form controls. If you are using a form control that has multiple inputs inside (for example, `IressCheckboxGroup`), you can use `IressFormFieldset`, which changes the HTML structure to use a `fieldset` and `legend` element to group the inputs.
|
|
175
178
|
|
|
179
|
+
[](./iframe.html?id=components-form--fields)
|
|
180
|
+
|
|
176
181
|
\*Required Name
|
|
177
182
|
|
|
178
183
|
\*Required Date
|
|
@@ -205,6 +210,8 @@ Salad
|
|
|
205
210
|
|
|
206
211
|
Type to copy an existing character's name
|
|
207
212
|
|
|
213
|
+
Type at least 1 character to search
|
|
214
|
+
|
|
208
215
|
\*Required Your star wars sidekick
|
|
209
216
|
|
|
210
217
|
None selected
|
|
@@ -221,11 +228,9 @@ None selected
|
|
|
221
228
|
|
|
222
229
|
Sign up
|
|
223
230
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
\[data-radix-scroll-area-viewport\] { scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; } \[data-radix-scroll-area-viewport\]::-webkit-scrollbar { display: none; } :where(\[data-radix-scroll-area-viewport\]) { display: flex; flex-direction: column; align-items: stretch; } :where(\[data-radix-scroll-area-content\]) { flex-grow: 1; }
|
|
231
|
+
```
|
|
227
232
|
|
|
228
|
-
<
|
|
233
|
+
<ForwardedForm\>
|
|
229
234
|
<IressStack gutter\="md"\>
|
|
230
235
|
<IressFormField
|
|
231
236
|
label\="Name"
|
|
@@ -393,31 +398,110 @@ Hide code
|
|
|
393
398
|
\>
|
|
394
399
|
Sign up </IressButton\>
|
|
395
400
|
</IressStack\>
|
|
396
|
-
</
|
|
401
|
+
</ForwardedForm\>
|
|
402
|
+
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
#### Props
|
|
406
|
+
|
|
407
|
+
| Name | Description | Default | Control |
|
|
408
|
+
| --- | --- | --- | --- |
|
|
409
|
+
| alert |
|
|
410
|
+
\-
|
|
411
|
+
|
|
412
|
+
| \- | Choose option...nonebasicAlert |
|
|
413
|
+
| children |
|
|
414
|
+
|
|
415
|
+
object
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
| \- | Choose option...nonesimplesupportedControlsreadOnly |
|
|
420
|
+
| form |
|
|
421
|
+
|
|
422
|
+
React hook form instance from `useForm`, use if you need more control over the internal state.
|
|
423
|
+
|
|
424
|
+
const form = useForm();
|
|
425
|
+
return <IressForm form={form} />;
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
UseFormReturn
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
| \- | Set object |
|
|
433
|
+
| Show React Hook Forms itemsReact Hook Forms | Show React Hook Forms items |
|
|
434
|
+
|
|
435
|
+
#### IressFormField props
|
|
436
|
+
|
|
437
|
+
| Name | Description | Default |
|
|
438
|
+
| --- | --- | --- |
|
|
439
|
+
| label |
|
|
440
|
+
string
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
| \- |
|
|
445
|
+
| name\* |
|
|
446
|
+
|
|
447
|
+
Name of the field. It is used to identify the field in the form. It must be unique within the form.
|
|
397
448
|
|
|
398
|
-
|
|
449
|
+
FieldPath
|
|
399
450
|
|
|
400
|
-
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
| \- |
|
|
454
|
+
| readOnly |
|
|
455
|
+
|
|
456
|
+
Text to be displayed instead of input field.
|
|
457
|
+
|
|
458
|
+
boolean
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
| \- |
|
|
463
|
+
| render\* |
|
|
464
|
+
|
|
465
|
+
Render function to provide the control for the field. To ensure the field is correctly registered with the form, the control must be passed as props to the rendered component. (eg. `render={field => <IressInput {...field} />}`)
|
|
466
|
+
|
|
467
|
+
(field: FormFieldRenderProps<T>) => ReactNode
|
|
468
|
+
|
|
469
|
+
| \- |
|
|
470
|
+
| rules |
|
|
471
|
+
|
|
472
|
+
Validation rules, including: required, min, max, minLength, maxLength, pattern, validate
|
|
473
|
+
|
|
474
|
+
[Learn more](https://react-hook-form.com/api/useform/register)
|
|
475
|
+
|
|
476
|
+
intersection
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
| \- |
|
|
481
|
+
| Show React Hook Forms itemsReact Hook Forms | Show React Hook Forms items |
|
|
482
|
+
| Show Field props itemsField props | Show Field props items |
|
|
483
|
+
|
|
484
|
+
### Rules
|
|
401
485
|
|
|
402
486
|
Use the `rules` prop on the `IressFormField` component to add validation rules. These are based on the [rules available in React Hook Forms](https://www.react-hook-form.com/api/useform/register/#options). The following rules are supported.
|
|
403
487
|
|
|
404
488
|
**Note:** In version 5, you can no longer override default error messages for the whole form. To override the default messages, you must specify them in the `rules` prop per `IressFormField`.
|
|
405
489
|
|
|
406
|
-
####
|
|
490
|
+
#### `required`
|
|
407
491
|
|
|
408
492
|
A boolean which, if `true`, indicates that the input must have a value before the form can be submitted. You can assign a string to return a custom error message.
|
|
409
493
|
|
|
494
|
+
[](./iframe.html?id=components-form-rules--required)
|
|
495
|
+
|
|
410
496
|
\*Required Default message
|
|
411
497
|
|
|
412
498
|
\*Required Custom message
|
|
413
499
|
|
|
414
500
|
Validate
|
|
415
501
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
\[data-radix-scroll-area-viewport\] { scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; } \[data-radix-scroll-area-viewport\]::-webkit-scrollbar { display: none; } :where(\[data-radix-scroll-area-viewport\]) { display: flex; flex-direction: column; align-items: stretch; } :where(\[data-radix-scroll-area-content\]) { flex-grow: 1; }
|
|
502
|
+
```
|
|
419
503
|
|
|
420
|
-
<
|
|
504
|
+
<ForwardedForm\>
|
|
421
505
|
<IressStack gutter\="lg"\>
|
|
422
506
|
<IressFormField
|
|
423
507
|
hint\=""
|
|
@@ -443,11 +527,17 @@ Hide code
|
|
|
443
527
|
\>
|
|
444
528
|
Validate </IressButton\>
|
|
445
529
|
</IressStack\>
|
|
446
|
-
</
|
|
530
|
+
</ForwardedForm\>
|
|
531
|
+
|
|
532
|
+
```
|
|
447
533
|
|
|
448
|
-
|
|
534
|
+
#### Adjust
|
|
449
535
|
|
|
450
|
-
|
|
536
|
+
| Name | Description | Default | Control |
|
|
537
|
+
| --- | --- | --- | --- |
|
|
538
|
+
| Show Storybook only itemsStorybook only | Show Storybook only items |
|
|
539
|
+
|
|
540
|
+
#### `maxLength`
|
|
451
541
|
|
|
452
542
|
The maximum character length of the value to accept for this input.
|
|
453
543
|
|
|
@@ -456,6 +546,8 @@ The maximum character length of the value to accept for this input.
|
|
|
456
546
|
* For `IressInput`, you should also set the `maxLength` to stop the user from entering more characters than allowed.
|
|
457
547
|
* Only applies to: `IressAutocomplete`, `IressInput`, `IressRadioGroup` and `IressSelect`.
|
|
458
548
|
|
|
549
|
+
[](./iframe.html?id=components-form-rules--max-length)
|
|
550
|
+
|
|
459
551
|
Default message
|
|
460
552
|
|
|
461
553
|
Enter a maximum length of 5 characters
|
|
@@ -466,11 +558,9 @@ Enter a maximum length of 5 characters
|
|
|
466
558
|
|
|
467
559
|
Validate
|
|
468
560
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
\[data-radix-scroll-area-viewport\] { scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; } \[data-radix-scroll-area-viewport\]::-webkit-scrollbar { display: none; } :where(\[data-radix-scroll-area-viewport\]) { display: flex; flex-direction: column; align-items: stretch; } :where(\[data-radix-scroll-area-content\]) { flex-grow: 1; }
|
|
561
|
+
```
|
|
472
562
|
|
|
473
|
-
<
|
|
563
|
+
<ForwardedForm\>
|
|
474
564
|
<IressStack gutter\="lg"\>
|
|
475
565
|
<IressFormField
|
|
476
566
|
hint\="Enter a maximum length of 5 characters"
|
|
@@ -499,11 +589,17 @@ Hide code
|
|
|
499
589
|
\>
|
|
500
590
|
Validate </IressButton\>
|
|
501
591
|
</IressStack\>
|
|
502
|
-
</
|
|
592
|
+
</ForwardedForm\>
|
|
503
593
|
|
|
504
|
-
|
|
594
|
+
```
|
|
505
595
|
|
|
506
|
-
####
|
|
596
|
+
#### Adjust
|
|
597
|
+
|
|
598
|
+
| Name | Description | Default | Control |
|
|
599
|
+
| --- | --- | --- | --- |
|
|
600
|
+
| Show Storybook only itemsStorybook only | Show Storybook only items |
|
|
601
|
+
|
|
602
|
+
#### `minLength`
|
|
507
603
|
|
|
508
604
|
The minimum character length of the value to accept for this input.
|
|
509
605
|
|
|
@@ -512,6 +608,8 @@ The minimum character length of the value to accept for this input.
|
|
|
512
608
|
* For `IressInput`, you should also set the `minLength` to stop the user from entering more characters than allowed.
|
|
513
609
|
* Only applies to: `IressAutocomplete`, `IressInput`, `IressRadioGroup` and `IressSelect`.
|
|
514
610
|
|
|
611
|
+
[](./iframe.html?id=components-form-rules--min-length)
|
|
612
|
+
|
|
515
613
|
Default message
|
|
516
614
|
|
|
517
615
|
Enter a minimum length of 7 characters
|
|
@@ -522,11 +620,9 @@ Enter a minimum length of 7 characters
|
|
|
522
620
|
|
|
523
621
|
Validate
|
|
524
622
|
|
|
525
|
-
|
|
623
|
+
```
|
|
526
624
|
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
<IressForm\>
|
|
625
|
+
<ForwardedForm\>
|
|
530
626
|
<IressStack gutter\="lg"\>
|
|
531
627
|
<IressFormField
|
|
532
628
|
hint\="Enter a minimum length of 7 characters"
|
|
@@ -555,11 +651,17 @@ Hide code
|
|
|
555
651
|
\>
|
|
556
652
|
Validate </IressButton\>
|
|
557
653
|
</IressStack\>
|
|
558
|
-
</
|
|
654
|
+
</ForwardedForm\>
|
|
655
|
+
|
|
656
|
+
```
|
|
559
657
|
|
|
560
|
-
|
|
658
|
+
#### Adjust
|
|
561
659
|
|
|
562
|
-
|
|
660
|
+
| Name | Description | Default | Control |
|
|
661
|
+
| --- | --- | --- | --- |
|
|
662
|
+
| Show Storybook only itemsStorybook only | Show Storybook only items |
|
|
663
|
+
|
|
664
|
+
#### `max`
|
|
563
665
|
|
|
564
666
|
The maximum number to accept for this input.
|
|
565
667
|
|
|
@@ -567,6 +669,8 @@ The maximum number to accept for this input.
|
|
|
567
669
|
|
|
568
670
|
* Only applies to: `IressAutocomplete`, `IressInput`, `IressRadioGroup` and `IressSelect`.
|
|
569
671
|
|
|
672
|
+
[](./iframe.html?id=components-form-rules--max)
|
|
673
|
+
|
|
570
674
|
Default message
|
|
571
675
|
|
|
572
676
|
Select a maximum of 2
|
|
@@ -577,11 +681,9 @@ Select a maximum of 2
|
|
|
577
681
|
|
|
578
682
|
Validate
|
|
579
683
|
|
|
580
|
-
|
|
684
|
+
```
|
|
581
685
|
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
<IressForm\>
|
|
686
|
+
<ForwardedForm\>
|
|
585
687
|
<IressStack gutter\="lg"\>
|
|
586
688
|
<IressFormField
|
|
587
689
|
hint\="Select a maximum of 2"
|
|
@@ -610,11 +712,17 @@ Hide code
|
|
|
610
712
|
\>
|
|
611
713
|
Validate </IressButton\>
|
|
612
714
|
</IressStack\>
|
|
613
|
-
</
|
|
715
|
+
</ForwardedForm\>
|
|
716
|
+
|
|
717
|
+
```
|
|
718
|
+
|
|
719
|
+
#### Adjust
|
|
614
720
|
|
|
615
|
-
|
|
721
|
+
| Name | Description | Default | Control |
|
|
722
|
+
| --- | --- | --- | --- |
|
|
723
|
+
| Show Storybook only itemsStorybook only | Show Storybook only items |
|
|
616
724
|
|
|
617
|
-
####
|
|
725
|
+
#### `min`
|
|
618
726
|
|
|
619
727
|
The minimum number to accept for this input.
|
|
620
728
|
|
|
@@ -622,6 +730,8 @@ The minimum number to accept for this input.
|
|
|
622
730
|
|
|
623
731
|
* Only applies to: `IressAutocomplete`, `IressInput`, `IressRadioGroup` and `IressSelect`.
|
|
624
732
|
|
|
733
|
+
[](./iframe.html?id=components-form-rules--min)
|
|
734
|
+
|
|
625
735
|
Default message
|
|
626
736
|
|
|
627
737
|
Select a minimum of 20
|
|
@@ -632,11 +742,9 @@ Select a minimum of 20
|
|
|
632
742
|
|
|
633
743
|
Validate
|
|
634
744
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
\[data-radix-scroll-area-viewport\] { scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; } \[data-radix-scroll-area-viewport\]::-webkit-scrollbar { display: none; } :where(\[data-radix-scroll-area-viewport\]) { display: flex; flex-direction: column; align-items: stretch; } :where(\[data-radix-scroll-area-content\]) { flex-grow: 1; }
|
|
745
|
+
```
|
|
638
746
|
|
|
639
|
-
<
|
|
747
|
+
<ForwardedForm\>
|
|
640
748
|
<IressStack gutter\="lg"\>
|
|
641
749
|
<IressFormField
|
|
642
750
|
hint\="Select a minimum of 20"
|
|
@@ -665,11 +773,17 @@ Hide code
|
|
|
665
773
|
\>
|
|
666
774
|
Validate </IressButton\>
|
|
667
775
|
</IressStack\>
|
|
668
|
-
</
|
|
776
|
+
</ForwardedForm\>
|
|
777
|
+
|
|
778
|
+
```
|
|
669
779
|
|
|
670
|
-
|
|
780
|
+
#### Adjust
|
|
671
781
|
|
|
672
|
-
|
|
782
|
+
| Name | Description | Default | Control |
|
|
783
|
+
| --- | --- | --- | --- |
|
|
784
|
+
| Show Storybook only itemsStorybook only | Show Storybook only items |
|
|
785
|
+
|
|
786
|
+
#### `pattern`
|
|
673
787
|
|
|
674
788
|
The accepted regex pattern for the input.
|
|
675
789
|
|
|
@@ -677,6 +791,8 @@ The accepted regex pattern for the input.
|
|
|
677
791
|
|
|
678
792
|
* Only applies to: `IressAutocomplete`, `IressInput`, `IressRadioGroup` and `IressSelect`.
|
|
679
793
|
|
|
794
|
+
[](./iframe.html?id=components-form-rules--pattern)
|
|
795
|
+
|
|
680
796
|
Default message
|
|
681
797
|
|
|
682
798
|
Enter a valid email address
|
|
@@ -687,11 +803,9 @@ Enter a valid email address
|
|
|
687
803
|
|
|
688
804
|
Validate
|
|
689
805
|
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
\[data-radix-scroll-area-viewport\] { scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; } \[data-radix-scroll-area-viewport\]::-webkit-scrollbar { display: none; } :where(\[data-radix-scroll-area-viewport\]) { display: flex; flex-direction: column; align-items: stretch; } :where(\[data-radix-scroll-area-content\]) { flex-grow: 1; }
|
|
806
|
+
```
|
|
693
807
|
|
|
694
|
-
<
|
|
808
|
+
<ForwardedForm\>
|
|
695
809
|
<IressStack gutter\="lg"\>
|
|
696
810
|
<IressFormField
|
|
697
811
|
hint\="Enter a valid email address"
|
|
@@ -715,16 +829,24 @@ Hide code
|
|
|
715
829
|
\>
|
|
716
830
|
Validate </IressButton\>
|
|
717
831
|
</IressStack\>
|
|
718
|
-
</
|
|
832
|
+
</ForwardedForm\>
|
|
719
833
|
|
|
720
|
-
|
|
834
|
+
```
|
|
721
835
|
|
|
722
|
-
####
|
|
836
|
+
#### Adjust
|
|
837
|
+
|
|
838
|
+
| Name | Description | Default | Control |
|
|
839
|
+
| --- | --- | --- | --- |
|
|
840
|
+
| Show Storybook only itemsStorybook only | Show Storybook only items |
|
|
841
|
+
|
|
842
|
+
#### `minDate`
|
|
723
843
|
|
|
724
844
|
The minimum date to accept for this input.
|
|
725
845
|
|
|
726
846
|
**Note:** This is a custom rule created for `IressForm` and its sub-components. It will translate the rule into a `validate` rule for react-hook-forms. It will not work with a `validate` function, only if you set the `validate` prop to an `object` of functions.
|
|
727
847
|
|
|
848
|
+
[](./iframe.html?id=components-form-rules--min-date)
|
|
849
|
+
|
|
728
850
|
Default message
|
|
729
851
|
|
|
730
852
|
Enter a date after today
|
|
@@ -735,11 +857,9 @@ Enter a date after today
|
|
|
735
857
|
|
|
736
858
|
Validate
|
|
737
859
|
|
|
738
|
-
|
|
860
|
+
```
|
|
739
861
|
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
<IressForm\>
|
|
862
|
+
<ForwardedForm\>
|
|
743
863
|
<IressStack gutter\="lg"\>
|
|
744
864
|
<IressFormField
|
|
745
865
|
hint\="Enter a date after today"
|
|
@@ -747,7 +867,7 @@ Hide code
|
|
|
747
867
|
name\="IressInputDate-default"
|
|
748
868
|
render\={(controlledProps) \=> <IressInput {...controlledProps} />}
|
|
749
869
|
rules\={{
|
|
750
|
-
minDate: new Date('2025-
|
|
870
|
+
minDate: new Date('2025-12-04T07:07:37.519Z')
|
|
751
871
|
}}
|
|
752
872
|
/>
|
|
753
873
|
<IressFormField
|
|
@@ -758,7 +878,7 @@ Hide code
|
|
|
758
878
|
rules\={{
|
|
759
879
|
minDate: {
|
|
760
880
|
message: 'Please enter a date after today!',
|
|
761
|
-
value: new Date('2025-
|
|
881
|
+
value: new Date('2025-12-04T07:07:37.519Z')
|
|
762
882
|
}
|
|
763
883
|
}}
|
|
764
884
|
/>
|
|
@@ -768,16 +888,169 @@ Hide code
|
|
|
768
888
|
\>
|
|
769
889
|
Validate </IressButton\>
|
|
770
890
|
</IressStack\>
|
|
771
|
-
</
|
|
891
|
+
</ForwardedForm\>
|
|
892
|
+
|
|
893
|
+
```
|
|
894
|
+
|
|
895
|
+
#### Props
|
|
896
|
+
|
|
897
|
+
| Name | Description | Default | Control |
|
|
898
|
+
| --- | --- | --- | --- |
|
|
899
|
+
| children |
|
|
900
|
+
\-
|
|
901
|
+
|
|
902
|
+
| \- | \- |
|
|
903
|
+
| context |
|
|
904
|
+
|
|
905
|
+
This context object is mutable and will be injected into the `resolver`'s second argument (eg. [Yup](https://github.com/jquense/yup) validation's context object).
|
|
906
|
+
|
|
907
|
+
[Learn more](https://react-hook-form.com/docs/useform#context)
|
|
908
|
+
|
|
909
|
+
UseFormProps\['context'\]
|
|
910
|
+
|
|
911
|
+
| \- | Set object |
|
|
912
|
+
| criteriaMode |
|
|
772
913
|
|
|
773
|
-
|
|
914
|
+
Display all validation errors or one at a time.
|
|
774
915
|
|
|
775
|
-
|
|
916
|
+
[Learn more](https://react-hook-form.com/docs/useform#criteriaMode)
|
|
917
|
+
|
|
918
|
+
UseFormProps\['criteriaMode'\]
|
|
919
|
+
|
|
920
|
+
| \- | Set object |
|
|
921
|
+
| defaultValues |
|
|
922
|
+
|
|
923
|
+
Default values to be passed through when an input is unset.
|
|
924
|
+
|
|
925
|
+
[Learn more](https://react-hook-form.com/docs/useform#defaultValues)
|
|
926
|
+
|
|
927
|
+
DefaultValues
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
| \- | Set object |
|
|
932
|
+
| delayError |
|
|
933
|
+
|
|
934
|
+
Delay error from appearing instantly.
|
|
935
|
+
|
|
936
|
+
[Learn more](https://react-hook-form.com/docs/useform#delayError)
|
|
937
|
+
|
|
938
|
+
UseFormProps\['delayError'\]
|
|
939
|
+
|
|
940
|
+
| \- | Set object |
|
|
941
|
+
| form |
|
|
942
|
+
|
|
943
|
+
React hook form instance from `useForm`, use if you need more control over the internal state.
|
|
944
|
+
|
|
945
|
+
const form = useForm();
|
|
946
|
+
return <IressForm form={form} />;
|
|
947
|
+
|
|
948
|
+
|
|
949
|
+
UseFormReturn
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
|
|
953
|
+
| \- | Set object |
|
|
954
|
+
| mode |
|
|
955
|
+
|
|
956
|
+
Configure the validation strategy **before** a user submits the form.
|
|
957
|
+
|
|
958
|
+
[Learn more](https://react-hook-form.com/docs/useform#mode)
|
|
959
|
+
|
|
960
|
+
UseFormProps\['mode'\]
|
|
961
|
+
|
|
962
|
+
|
|
|
963
|
+
|
|
964
|
+
'onSubmit'
|
|
965
|
+
|
|
966
|
+
| Set object |
|
|
967
|
+
| progressive |
|
|
968
|
+
|
|
969
|
+
Progressive Enhancement only applicable for SSR framework. [Learn more](https://react-hook-form.com/docs/useform)
|
|
970
|
+
|
|
971
|
+
UseFormProps\['progressive'\]
|
|
972
|
+
|
|
973
|
+
| \- | Set object |
|
|
974
|
+
| resetOptions |
|
|
975
|
+
|
|
976
|
+
This property is related to value update behaviors.
|
|
977
|
+
|
|
978
|
+
[Learn more](https://react-hook-form.com/docs/useform#resetOptions)
|
|
979
|
+
|
|
980
|
+
UseFormProps\['resetOptions'\]
|
|
981
|
+
|
|
982
|
+
| \- | Set object |
|
|
983
|
+
| resolver |
|
|
984
|
+
|
|
985
|
+
This function allows you to use any external validation library such as Yup, Zod, Joi, Vest, Ajv and many others.
|
|
986
|
+
|
|
987
|
+
[Learn more](https://react-hook-form.com/docs/useform#resolver)
|
|
988
|
+
|
|
989
|
+
UseFormProps\['resolver'\]
|
|
990
|
+
|
|
991
|
+
| \- | Set object |
|
|
992
|
+
| reValidateMode |
|
|
993
|
+
|
|
994
|
+
Configure validation strategy when inputs with errors get re-validated **after** a user submits the form.
|
|
995
|
+
|
|
996
|
+
[Learn more](https://react-hook-form.com/docs/useform#reValidateMode)
|
|
997
|
+
|
|
998
|
+
UseFormProps\['reValidateMode'\]
|
|
999
|
+
|
|
1000
|
+
|
|
|
1001
|
+
|
|
1002
|
+
'onChange'
|
|
1003
|
+
|
|
1004
|
+
| Set object |
|
|
1005
|
+
| shouldFocusError |
|
|
1006
|
+
|
|
1007
|
+
When set to true, and the user submits a form that fails validation, focus is set on the first field with an error. By default, it is set based on the `hiddenErrorSummary` prop.
|
|
1008
|
+
|
|
1009
|
+
* If hiddenErrorSummary is true, it will focus on the first field with an error.
|
|
1010
|
+
* If hiddenErrorSummary is false, it will focus on the error summary.
|
|
1011
|
+
|
|
1012
|
+
[Learn more](https://react-hook-form.com/docs/useform#shouldFocusError)
|
|
1013
|
+
|
|
1014
|
+
UseFormProps\['shouldFocusError'\]
|
|
1015
|
+
|
|
1016
|
+
| \- | Set object |
|
|
1017
|
+
| shouldUnregister |
|
|
1018
|
+
|
|
1019
|
+
By default, an input value will be retained when input is removed. However, you can set `shouldUnregister` to `true` to `unregister` input during unmount.
|
|
1020
|
+
|
|
1021
|
+
[Learn more](https://react-hook-form.com/docs/useform#shouldUnregister)
|
|
1022
|
+
|
|
1023
|
+
UseFormProps\['shouldUnregister'\]
|
|
1024
|
+
|
|
1025
|
+
| \- | Set object |
|
|
1026
|
+
| shouldUseNativeValidation |
|
|
1027
|
+
|
|
1028
|
+
This config will enable browser native validation. It will also enable CSS selectors :valid and:invalid making styling inputs easier.
|
|
1029
|
+
|
|
1030
|
+
[Learn more](https://react-hook-form.com/docs/useform#shouldUseNativeValidation)
|
|
1031
|
+
|
|
1032
|
+
UseFormProps\['shouldUseNativeValidation'\]
|
|
1033
|
+
|
|
1034
|
+
| \- | Set object |
|
|
1035
|
+
| values |
|
|
1036
|
+
|
|
1037
|
+
The values prop will react to changes and update the form values, which is useful when your form needs to be updated by external state or server data.
|
|
1038
|
+
|
|
1039
|
+
[Learn more](https://react-hook-form.com/docs/useform#values)
|
|
1040
|
+
|
|
1041
|
+
UseFormProps\['values'\]
|
|
1042
|
+
|
|
1043
|
+
| \- | Set object |
|
|
1044
|
+
| Show Storybook only itemsStorybook only | Show Storybook only items |
|
|
1045
|
+
|
|
1046
|
+
#### `maxDate`
|
|
776
1047
|
|
|
777
1048
|
The maximum date to accept for this input.
|
|
778
1049
|
|
|
779
1050
|
**Note:** This is a custom rule created for `IressForm` and its sub-components. It will translate the rule into a `validate` rule for react-hook-forms. It will not work with a `validate` function, only if you set the `validate` prop to an `object` of functions.
|
|
780
1051
|
|
|
1052
|
+
[](./iframe.html?id=components-form-rules--max-date)
|
|
1053
|
+
|
|
781
1054
|
Default message
|
|
782
1055
|
|
|
783
1056
|
Enter a date before today
|
|
@@ -788,11 +1061,9 @@ Enter a date before today
|
|
|
788
1061
|
|
|
789
1062
|
Validate
|
|
790
1063
|
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
\[data-radix-scroll-area-viewport\] { scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; } \[data-radix-scroll-area-viewport\]::-webkit-scrollbar { display: none; } :where(\[data-radix-scroll-area-viewport\]) { display: flex; flex-direction: column; align-items: stretch; } :where(\[data-radix-scroll-area-content\]) { flex-grow: 1; }
|
|
1064
|
+
```
|
|
794
1065
|
|
|
795
|
-
<
|
|
1066
|
+
<ForwardedForm\>
|
|
796
1067
|
<IressStack gutter\="lg"\>
|
|
797
1068
|
<IressFormField
|
|
798
1069
|
hint\="Enter a date before today"
|
|
@@ -800,7 +1071,7 @@ Hide code
|
|
|
800
1071
|
name\="IressInputDate-default"
|
|
801
1072
|
render\={(controlledProps) \=> <IressInput {...controlledProps} />}
|
|
802
1073
|
rules\={{
|
|
803
|
-
maxDate: new Date('2025-
|
|
1074
|
+
maxDate: new Date('2025-12-04T07:07:37.519Z')
|
|
804
1075
|
}}
|
|
805
1076
|
/>
|
|
806
1077
|
<IressFormField
|
|
@@ -811,7 +1082,7 @@ Hide code
|
|
|
811
1082
|
rules\={{
|
|
812
1083
|
maxDate: {
|
|
813
1084
|
message: 'Please enter a date before today!',
|
|
814
|
-
value: new Date('2025-
|
|
1085
|
+
value: new Date('2025-12-04T07:07:37.519Z')
|
|
815
1086
|
}
|
|
816
1087
|
}}
|
|
817
1088
|
/>
|
|
@@ -821,16 +1092,169 @@ Hide code
|
|
|
821
1092
|
\>
|
|
822
1093
|
Validate </IressButton\>
|
|
823
1094
|
</IressStack\>
|
|
824
|
-
</
|
|
1095
|
+
</ForwardedForm\>
|
|
1096
|
+
|
|
1097
|
+
```
|
|
1098
|
+
|
|
1099
|
+
#### Props
|
|
1100
|
+
|
|
1101
|
+
| Name | Description | Default | Control |
|
|
1102
|
+
| --- | --- | --- | --- |
|
|
1103
|
+
| children |
|
|
1104
|
+
\-
|
|
1105
|
+
|
|
1106
|
+
| \- | \- |
|
|
1107
|
+
| context |
|
|
1108
|
+
|
|
1109
|
+
This context object is mutable and will be injected into the `resolver`'s second argument (eg. [Yup](https://github.com/jquense/yup) validation's context object).
|
|
1110
|
+
|
|
1111
|
+
[Learn more](https://react-hook-form.com/docs/useform#context)
|
|
1112
|
+
|
|
1113
|
+
UseFormProps\['context'\]
|
|
1114
|
+
|
|
1115
|
+
| \- | Set object |
|
|
1116
|
+
| criteriaMode |
|
|
1117
|
+
|
|
1118
|
+
Display all validation errors or one at a time.
|
|
1119
|
+
|
|
1120
|
+
[Learn more](https://react-hook-form.com/docs/useform#criteriaMode)
|
|
1121
|
+
|
|
1122
|
+
UseFormProps\['criteriaMode'\]
|
|
1123
|
+
|
|
1124
|
+
| \- | Set object |
|
|
1125
|
+
| defaultValues |
|
|
1126
|
+
|
|
1127
|
+
Default values to be passed through when an input is unset.
|
|
1128
|
+
|
|
1129
|
+
[Learn more](https://react-hook-form.com/docs/useform#defaultValues)
|
|
1130
|
+
|
|
1131
|
+
DefaultValues
|
|
1132
|
+
|
|
1133
|
+
|
|
1134
|
+
|
|
1135
|
+
| \- | Set object |
|
|
1136
|
+
| delayError |
|
|
1137
|
+
|
|
1138
|
+
Delay error from appearing instantly.
|
|
1139
|
+
|
|
1140
|
+
[Learn more](https://react-hook-form.com/docs/useform#delayError)
|
|
1141
|
+
|
|
1142
|
+
UseFormProps\['delayError'\]
|
|
1143
|
+
|
|
1144
|
+
| \- | Set object |
|
|
1145
|
+
| form |
|
|
1146
|
+
|
|
1147
|
+
React hook form instance from `useForm`, use if you need more control over the internal state.
|
|
1148
|
+
|
|
1149
|
+
const form = useForm();
|
|
1150
|
+
return <IressForm form={form} />;
|
|
1151
|
+
|
|
1152
|
+
|
|
1153
|
+
UseFormReturn
|
|
1154
|
+
|
|
1155
|
+
|
|
1156
|
+
|
|
1157
|
+
| \- | Set object |
|
|
1158
|
+
| mode |
|
|
1159
|
+
|
|
1160
|
+
Configure the validation strategy **before** a user submits the form.
|
|
1161
|
+
|
|
1162
|
+
[Learn more](https://react-hook-form.com/docs/useform#mode)
|
|
1163
|
+
|
|
1164
|
+
UseFormProps\['mode'\]
|
|
1165
|
+
|
|
1166
|
+
|
|
|
1167
|
+
|
|
1168
|
+
'onSubmit'
|
|
1169
|
+
|
|
1170
|
+
| Set object |
|
|
1171
|
+
| progressive |
|
|
1172
|
+
|
|
1173
|
+
Progressive Enhancement only applicable for SSR framework. [Learn more](https://react-hook-form.com/docs/useform)
|
|
1174
|
+
|
|
1175
|
+
UseFormProps\['progressive'\]
|
|
1176
|
+
|
|
1177
|
+
| \- | Set object |
|
|
1178
|
+
| resetOptions |
|
|
1179
|
+
|
|
1180
|
+
This property is related to value update behaviors.
|
|
1181
|
+
|
|
1182
|
+
[Learn more](https://react-hook-form.com/docs/useform#resetOptions)
|
|
1183
|
+
|
|
1184
|
+
UseFormProps\['resetOptions'\]
|
|
1185
|
+
|
|
1186
|
+
| \- | Set object |
|
|
1187
|
+
| resolver |
|
|
825
1188
|
|
|
826
|
-
|
|
1189
|
+
This function allows you to use any external validation library such as Yup, Zod, Joi, Vest, Ajv and many others.
|
|
827
1190
|
|
|
828
|
-
|
|
1191
|
+
[Learn more](https://react-hook-form.com/docs/useform#resolver)
|
|
1192
|
+
|
|
1193
|
+
UseFormProps\['resolver'\]
|
|
1194
|
+
|
|
1195
|
+
| \- | Set object |
|
|
1196
|
+
| reValidateMode |
|
|
1197
|
+
|
|
1198
|
+
Configure validation strategy when inputs with errors get re-validated **after** a user submits the form.
|
|
1199
|
+
|
|
1200
|
+
[Learn more](https://react-hook-form.com/docs/useform#reValidateMode)
|
|
1201
|
+
|
|
1202
|
+
UseFormProps\['reValidateMode'\]
|
|
1203
|
+
|
|
1204
|
+
|
|
|
1205
|
+
|
|
1206
|
+
'onChange'
|
|
1207
|
+
|
|
1208
|
+
| Set object |
|
|
1209
|
+
| shouldFocusError |
|
|
1210
|
+
|
|
1211
|
+
When set to true, and the user submits a form that fails validation, focus is set on the first field with an error. By default, it is set based on the `hiddenErrorSummary` prop.
|
|
1212
|
+
|
|
1213
|
+
* If hiddenErrorSummary is true, it will focus on the first field with an error.
|
|
1214
|
+
* If hiddenErrorSummary is false, it will focus on the error summary.
|
|
1215
|
+
|
|
1216
|
+
[Learn more](https://react-hook-form.com/docs/useform#shouldFocusError)
|
|
1217
|
+
|
|
1218
|
+
UseFormProps\['shouldFocusError'\]
|
|
1219
|
+
|
|
1220
|
+
| \- | Set object |
|
|
1221
|
+
| shouldUnregister |
|
|
1222
|
+
|
|
1223
|
+
By default, an input value will be retained when input is removed. However, you can set `shouldUnregister` to `true` to `unregister` input during unmount.
|
|
1224
|
+
|
|
1225
|
+
[Learn more](https://react-hook-form.com/docs/useform#shouldUnregister)
|
|
1226
|
+
|
|
1227
|
+
UseFormProps\['shouldUnregister'\]
|
|
1228
|
+
|
|
1229
|
+
| \- | Set object |
|
|
1230
|
+
| shouldUseNativeValidation |
|
|
1231
|
+
|
|
1232
|
+
This config will enable browser native validation. It will also enable CSS selectors :valid and:invalid making styling inputs easier.
|
|
1233
|
+
|
|
1234
|
+
[Learn more](https://react-hook-form.com/docs/useform#shouldUseNativeValidation)
|
|
1235
|
+
|
|
1236
|
+
UseFormProps\['shouldUseNativeValidation'\]
|
|
1237
|
+
|
|
1238
|
+
| \- | Set object |
|
|
1239
|
+
| values |
|
|
1240
|
+
|
|
1241
|
+
The values prop will react to changes and update the form values, which is useful when your form needs to be updated by external state or server data.
|
|
1242
|
+
|
|
1243
|
+
[Learn more](https://react-hook-form.com/docs/useform#values)
|
|
1244
|
+
|
|
1245
|
+
UseFormProps\['values'\]
|
|
1246
|
+
|
|
1247
|
+
| \- | Set object |
|
|
1248
|
+
| Show Storybook only itemsStorybook only | Show Storybook only items |
|
|
1249
|
+
|
|
1250
|
+
#### `email`
|
|
829
1251
|
|
|
830
1252
|
Ensures the input is a valid email address.
|
|
831
1253
|
|
|
832
1254
|
**Note:** This is a custom rule created for `IressForm` and its sub-components. It will translate the rule into a `validate` rule for react-hook-forms. It will not work with a `validate` function, only if you set the `validate` prop to an `object` of functions.
|
|
833
1255
|
|
|
1256
|
+
[](./iframe.html?id=components-form-rules--email)
|
|
1257
|
+
|
|
834
1258
|
Default message
|
|
835
1259
|
|
|
836
1260
|
Enter an email address
|
|
@@ -841,11 +1265,9 @@ Enter an email address
|
|
|
841
1265
|
|
|
842
1266
|
Validate
|
|
843
1267
|
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
\[data-radix-scroll-area-viewport\] { scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; } \[data-radix-scroll-area-viewport\]::-webkit-scrollbar { display: none; } :where(\[data-radix-scroll-area-viewport\]) { display: flex; flex-direction: column; align-items: stretch; } :where(\[data-radix-scroll-area-content\]) { flex-grow: 1; }
|
|
1268
|
+
```
|
|
847
1269
|
|
|
848
|
-
<
|
|
1270
|
+
<ForwardedForm\>
|
|
849
1271
|
<IressStack gutter\="lg"\>
|
|
850
1272
|
<IressFormField
|
|
851
1273
|
hint\="Enter an email address"
|
|
@@ -871,11 +1293,162 @@ Hide code
|
|
|
871
1293
|
\>
|
|
872
1294
|
Validate </IressButton\>
|
|
873
1295
|
</IressStack\>
|
|
874
|
-
</
|
|
1296
|
+
</ForwardedForm\>
|
|
1297
|
+
|
|
1298
|
+
```
|
|
1299
|
+
|
|
1300
|
+
#### Props
|
|
1301
|
+
|
|
1302
|
+
| Name | Description | Default | Control |
|
|
1303
|
+
| --- | --- | --- | --- |
|
|
1304
|
+
| children |
|
|
1305
|
+
\-
|
|
1306
|
+
|
|
1307
|
+
| \- | \- |
|
|
1308
|
+
| context |
|
|
1309
|
+
|
|
1310
|
+
This context object is mutable and will be injected into the `resolver`'s second argument (eg. [Yup](https://github.com/jquense/yup) validation's context object).
|
|
1311
|
+
|
|
1312
|
+
[Learn more](https://react-hook-form.com/docs/useform#context)
|
|
1313
|
+
|
|
1314
|
+
UseFormProps\['context'\]
|
|
1315
|
+
|
|
1316
|
+
| \- | Set object |
|
|
1317
|
+
| criteriaMode |
|
|
1318
|
+
|
|
1319
|
+
Display all validation errors or one at a time.
|
|
1320
|
+
|
|
1321
|
+
[Learn more](https://react-hook-form.com/docs/useform#criteriaMode)
|
|
1322
|
+
|
|
1323
|
+
UseFormProps\['criteriaMode'\]
|
|
1324
|
+
|
|
1325
|
+
| \- | Set object |
|
|
1326
|
+
| defaultValues |
|
|
1327
|
+
|
|
1328
|
+
Default values to be passed through when an input is unset.
|
|
1329
|
+
|
|
1330
|
+
[Learn more](https://react-hook-form.com/docs/useform#defaultValues)
|
|
1331
|
+
|
|
1332
|
+
DefaultValues
|
|
1333
|
+
|
|
1334
|
+
|
|
1335
|
+
|
|
1336
|
+
| \- | Set object |
|
|
1337
|
+
| delayError |
|
|
1338
|
+
|
|
1339
|
+
Delay error from appearing instantly.
|
|
1340
|
+
|
|
1341
|
+
[Learn more](https://react-hook-form.com/docs/useform#delayError)
|
|
1342
|
+
|
|
1343
|
+
UseFormProps\['delayError'\]
|
|
1344
|
+
|
|
1345
|
+
| \- | Set object |
|
|
1346
|
+
| form |
|
|
1347
|
+
|
|
1348
|
+
React hook form instance from `useForm`, use if you need more control over the internal state.
|
|
875
1349
|
|
|
876
|
-
|
|
1350
|
+
const form = useForm();
|
|
1351
|
+
return <IressForm form={form} />;
|
|
1352
|
+
|
|
877
1353
|
|
|
878
|
-
|
|
1354
|
+
UseFormReturn
|
|
1355
|
+
|
|
1356
|
+
|
|
1357
|
+
|
|
1358
|
+
| \- | Set object |
|
|
1359
|
+
| mode |
|
|
1360
|
+
|
|
1361
|
+
Configure the validation strategy **before** a user submits the form.
|
|
1362
|
+
|
|
1363
|
+
[Learn more](https://react-hook-form.com/docs/useform#mode)
|
|
1364
|
+
|
|
1365
|
+
UseFormProps\['mode'\]
|
|
1366
|
+
|
|
1367
|
+
|
|
|
1368
|
+
|
|
1369
|
+
'onSubmit'
|
|
1370
|
+
|
|
1371
|
+
| Set object |
|
|
1372
|
+
| progressive |
|
|
1373
|
+
|
|
1374
|
+
Progressive Enhancement only applicable for SSR framework. [Learn more](https://react-hook-form.com/docs/useform)
|
|
1375
|
+
|
|
1376
|
+
UseFormProps\['progressive'\]
|
|
1377
|
+
|
|
1378
|
+
| \- | Set object |
|
|
1379
|
+
| resetOptions |
|
|
1380
|
+
|
|
1381
|
+
This property is related to value update behaviors.
|
|
1382
|
+
|
|
1383
|
+
[Learn more](https://react-hook-form.com/docs/useform#resetOptions)
|
|
1384
|
+
|
|
1385
|
+
UseFormProps\['resetOptions'\]
|
|
1386
|
+
|
|
1387
|
+
| \- | Set object |
|
|
1388
|
+
| resolver |
|
|
1389
|
+
|
|
1390
|
+
This function allows you to use any external validation library such as Yup, Zod, Joi, Vest, Ajv and many others.
|
|
1391
|
+
|
|
1392
|
+
[Learn more](https://react-hook-form.com/docs/useform#resolver)
|
|
1393
|
+
|
|
1394
|
+
UseFormProps\['resolver'\]
|
|
1395
|
+
|
|
1396
|
+
| \- | Set object |
|
|
1397
|
+
| reValidateMode |
|
|
1398
|
+
|
|
1399
|
+
Configure validation strategy when inputs with errors get re-validated **after** a user submits the form.
|
|
1400
|
+
|
|
1401
|
+
[Learn more](https://react-hook-form.com/docs/useform#reValidateMode)
|
|
1402
|
+
|
|
1403
|
+
UseFormProps\['reValidateMode'\]
|
|
1404
|
+
|
|
1405
|
+
|
|
|
1406
|
+
|
|
1407
|
+
'onChange'
|
|
1408
|
+
|
|
1409
|
+
| Set object |
|
|
1410
|
+
| shouldFocusError |
|
|
1411
|
+
|
|
1412
|
+
When set to true, and the user submits a form that fails validation, focus is set on the first field with an error. By default, it is set based on the `hiddenErrorSummary` prop.
|
|
1413
|
+
|
|
1414
|
+
* If hiddenErrorSummary is true, it will focus on the first field with an error.
|
|
1415
|
+
* If hiddenErrorSummary is false, it will focus on the error summary.
|
|
1416
|
+
|
|
1417
|
+
[Learn more](https://react-hook-form.com/docs/useform#shouldFocusError)
|
|
1418
|
+
|
|
1419
|
+
UseFormProps\['shouldFocusError'\]
|
|
1420
|
+
|
|
1421
|
+
| \- | Set object |
|
|
1422
|
+
| shouldUnregister |
|
|
1423
|
+
|
|
1424
|
+
By default, an input value will be retained when input is removed. However, you can set `shouldUnregister` to `true` to `unregister` input during unmount.
|
|
1425
|
+
|
|
1426
|
+
[Learn more](https://react-hook-form.com/docs/useform#shouldUnregister)
|
|
1427
|
+
|
|
1428
|
+
UseFormProps\['shouldUnregister'\]
|
|
1429
|
+
|
|
1430
|
+
| \- | Set object |
|
|
1431
|
+
| shouldUseNativeValidation |
|
|
1432
|
+
|
|
1433
|
+
This config will enable browser native validation. It will also enable CSS selectors :valid and:invalid making styling inputs easier.
|
|
1434
|
+
|
|
1435
|
+
[Learn more](https://react-hook-form.com/docs/useform#shouldUseNativeValidation)
|
|
1436
|
+
|
|
1437
|
+
UseFormProps\['shouldUseNativeValidation'\]
|
|
1438
|
+
|
|
1439
|
+
| \- | Set object |
|
|
1440
|
+
| values |
|
|
1441
|
+
|
|
1442
|
+
The values prop will react to changes and update the form values, which is useful when your form needs to be updated by external state or server data.
|
|
1443
|
+
|
|
1444
|
+
[Learn more](https://react-hook-form.com/docs/useform#values)
|
|
1445
|
+
|
|
1446
|
+
UseFormProps\['values'\]
|
|
1447
|
+
|
|
1448
|
+
| \- | Set object |
|
|
1449
|
+
| Show Storybook only itemsStorybook only | Show Storybook only items |
|
|
1450
|
+
|
|
1451
|
+
#### `validate`
|
|
879
1452
|
|
|
880
1453
|
You can pass a callback function as the argument to validate, or you can pass an object of callback functions to validate against all of them. This function will be executed on its own without depending on other validation rules included.
|
|
881
1454
|
|
|
@@ -883,6 +1456,8 @@ You can pass a callback function as the argument to validate, or you can pass an
|
|
|
883
1456
|
|
|
884
1457
|
* for `object` or `array` input data, it's recommended to use the validate function for validation as the other rules mostly apply to `string`, `string[]`, `number` and `boolean` data types.
|
|
885
1458
|
|
|
1459
|
+
[](./iframe.html?id=components-form-rules--validate)
|
|
1460
|
+
|
|
886
1461
|
Default message
|
|
887
1462
|
|
|
888
1463
|
If checkbox, click two items to pass. Anything else, make sure it is Google.
|
|
@@ -901,11 +1476,9 @@ Writing
|
|
|
901
1476
|
|
|
902
1477
|
Validate
|
|
903
1478
|
|
|
904
|
-
|
|
1479
|
+
```
|
|
905
1480
|
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
<IressForm\>
|
|
1481
|
+
<ForwardedForm\>
|
|
909
1482
|
<IressStack gutter\="lg"\>
|
|
910
1483
|
<IressFormFieldset
|
|
911
1484
|
hint\="If checkbox, click two items to pass. Anything else, make sure it is Google."
|
|
@@ -947,27 +1520,178 @@ Hide code
|
|
|
947
1520
|
\>
|
|
948
1521
|
Validate </IressButton\>
|
|
949
1522
|
</IressStack\>
|
|
950
|
-
</
|
|
1523
|
+
</ForwardedForm\>
|
|
1524
|
+
|
|
1525
|
+
```
|
|
1526
|
+
|
|
1527
|
+
#### Props
|
|
1528
|
+
|
|
1529
|
+
| Name | Description | Default | Control |
|
|
1530
|
+
| --- | --- | --- | --- |
|
|
1531
|
+
| children |
|
|
1532
|
+
\-
|
|
1533
|
+
|
|
1534
|
+
| \- | \- |
|
|
1535
|
+
| context |
|
|
1536
|
+
|
|
1537
|
+
This context object is mutable and will be injected into the `resolver`'s second argument (eg. [Yup](https://github.com/jquense/yup) validation's context object).
|
|
951
1538
|
|
|
952
|
-
|
|
1539
|
+
[Learn more](https://react-hook-form.com/docs/useform#context)
|
|
953
1540
|
|
|
954
|
-
|
|
1541
|
+
UseFormProps\['context'\]
|
|
1542
|
+
|
|
1543
|
+
| \- | Set object |
|
|
1544
|
+
| criteriaMode |
|
|
1545
|
+
|
|
1546
|
+
Display all validation errors or one at a time.
|
|
1547
|
+
|
|
1548
|
+
[Learn more](https://react-hook-form.com/docs/useform#criteriaMode)
|
|
1549
|
+
|
|
1550
|
+
UseFormProps\['criteriaMode'\]
|
|
1551
|
+
|
|
1552
|
+
| \- | Set object |
|
|
1553
|
+
| defaultValues |
|
|
1554
|
+
|
|
1555
|
+
Default values to be passed through when an input is unset.
|
|
1556
|
+
|
|
1557
|
+
[Learn more](https://react-hook-form.com/docs/useform#defaultValues)
|
|
1558
|
+
|
|
1559
|
+
DefaultValues
|
|
1560
|
+
|
|
1561
|
+
|
|
1562
|
+
|
|
1563
|
+
| \- | Set object |
|
|
1564
|
+
| delayError |
|
|
1565
|
+
|
|
1566
|
+
Delay error from appearing instantly.
|
|
1567
|
+
|
|
1568
|
+
[Learn more](https://react-hook-form.com/docs/useform#delayError)
|
|
1569
|
+
|
|
1570
|
+
UseFormProps\['delayError'\]
|
|
1571
|
+
|
|
1572
|
+
| \- | Set object |
|
|
1573
|
+
| form |
|
|
1574
|
+
|
|
1575
|
+
React hook form instance from `useForm`, use if you need more control over the internal state.
|
|
1576
|
+
|
|
1577
|
+
const form = useForm();
|
|
1578
|
+
return <IressForm form={form} />;
|
|
1579
|
+
|
|
1580
|
+
|
|
1581
|
+
UseFormReturn
|
|
1582
|
+
|
|
1583
|
+
|
|
1584
|
+
|
|
1585
|
+
| \- | Set object |
|
|
1586
|
+
| mode |
|
|
1587
|
+
|
|
1588
|
+
Configure the validation strategy **before** a user submits the form.
|
|
1589
|
+
|
|
1590
|
+
[Learn more](https://react-hook-form.com/docs/useform#mode)
|
|
1591
|
+
|
|
1592
|
+
UseFormProps\['mode'\]
|
|
1593
|
+
|
|
1594
|
+
|
|
|
1595
|
+
|
|
1596
|
+
'onSubmit'
|
|
1597
|
+
|
|
1598
|
+
| Set object |
|
|
1599
|
+
| progressive |
|
|
1600
|
+
|
|
1601
|
+
Progressive Enhancement only applicable for SSR framework. [Learn more](https://react-hook-form.com/docs/useform)
|
|
1602
|
+
|
|
1603
|
+
UseFormProps\['progressive'\]
|
|
1604
|
+
|
|
1605
|
+
| \- | Set object |
|
|
1606
|
+
| resetOptions |
|
|
1607
|
+
|
|
1608
|
+
This property is related to value update behaviors.
|
|
1609
|
+
|
|
1610
|
+
[Learn more](https://react-hook-form.com/docs/useform#resetOptions)
|
|
1611
|
+
|
|
1612
|
+
UseFormProps\['resetOptions'\]
|
|
1613
|
+
|
|
1614
|
+
| \- | Set object |
|
|
1615
|
+
| resolver |
|
|
1616
|
+
|
|
1617
|
+
This function allows you to use any external validation library such as Yup, Zod, Joi, Vest, Ajv and many others.
|
|
1618
|
+
|
|
1619
|
+
[Learn more](https://react-hook-form.com/docs/useform#resolver)
|
|
1620
|
+
|
|
1621
|
+
UseFormProps\['resolver'\]
|
|
1622
|
+
|
|
1623
|
+
| \- | Set object |
|
|
1624
|
+
| reValidateMode |
|
|
1625
|
+
|
|
1626
|
+
Configure validation strategy when inputs with errors get re-validated **after** a user submits the form.
|
|
1627
|
+
|
|
1628
|
+
[Learn more](https://react-hook-form.com/docs/useform#reValidateMode)
|
|
1629
|
+
|
|
1630
|
+
UseFormProps\['reValidateMode'\]
|
|
1631
|
+
|
|
1632
|
+
|
|
|
1633
|
+
|
|
1634
|
+
'onChange'
|
|
1635
|
+
|
|
1636
|
+
| Set object |
|
|
1637
|
+
| shouldFocusError |
|
|
1638
|
+
|
|
1639
|
+
When set to true, and the user submits a form that fails validation, focus is set on the first field with an error. By default, it is set based on the `hiddenErrorSummary` prop.
|
|
1640
|
+
|
|
1641
|
+
* If hiddenErrorSummary is true, it will focus on the first field with an error.
|
|
1642
|
+
* If hiddenErrorSummary is false, it will focus on the error summary.
|
|
1643
|
+
|
|
1644
|
+
[Learn more](https://react-hook-form.com/docs/useform#shouldFocusError)
|
|
1645
|
+
|
|
1646
|
+
UseFormProps\['shouldFocusError'\]
|
|
1647
|
+
|
|
1648
|
+
| \- | Set object |
|
|
1649
|
+
| shouldUnregister |
|
|
1650
|
+
|
|
1651
|
+
By default, an input value will be retained when input is removed. However, you can set `shouldUnregister` to `true` to `unregister` input during unmount.
|
|
1652
|
+
|
|
1653
|
+
[Learn more](https://react-hook-form.com/docs/useform#shouldUnregister)
|
|
1654
|
+
|
|
1655
|
+
UseFormProps\['shouldUnregister'\]
|
|
1656
|
+
|
|
1657
|
+
| \- | Set object |
|
|
1658
|
+
| shouldUseNativeValidation |
|
|
1659
|
+
|
|
1660
|
+
This config will enable browser native validation. It will also enable CSS selectors :valid and:invalid making styling inputs easier.
|
|
1661
|
+
|
|
1662
|
+
[Learn more](https://react-hook-form.com/docs/useform#shouldUseNativeValidation)
|
|
1663
|
+
|
|
1664
|
+
UseFormProps\['shouldUseNativeValidation'\]
|
|
1665
|
+
|
|
1666
|
+
| \- | Set object |
|
|
1667
|
+
| values |
|
|
1668
|
+
|
|
1669
|
+
The values prop will react to changes and update the form values, which is useful when your form needs to be updated by external state or server data.
|
|
1670
|
+
|
|
1671
|
+
[Learn more](https://react-hook-form.com/docs/useform#values)
|
|
1672
|
+
|
|
1673
|
+
UseFormProps\['values'\]
|
|
1674
|
+
|
|
1675
|
+
| \- | Set object |
|
|
1676
|
+
| Show Storybook only itemsStorybook only | Show Storybook only items |
|
|
1677
|
+
|
|
1678
|
+
### Handling submission
|
|
955
1679
|
|
|
956
1680
|
When the form passes validation (if not disabled), the `onSubmit` event is emitted. Its event details contain a map of the field names and the data entered by the user.
|
|
957
1681
|
|
|
1682
|
+
[](./iframe.html?id=components-form--handling-submission)
|
|
1683
|
+
|
|
958
1684
|
\*Required Name
|
|
959
1685
|
|
|
960
1686
|
\*Required Email address
|
|
961
1687
|
|
|
962
1688
|
Sign up
|
|
963
1689
|
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
\[data-radix-scroll-area-viewport\] { scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; } \[data-radix-scroll-area-viewport\]::-webkit-scrollbar { display: none; } :where(\[data-radix-scroll-area-viewport\]) { display: flex; flex-direction: column; align-items: stretch; } :where(\[data-radix-scroll-area-content\]) { flex-grow: 1; }
|
|
1690
|
+
```
|
|
967
1691
|
|
|
968
1692
|
import {
|
|
969
1693
|
IressTable,
|
|
970
|
-
IressFormProps,
|
|
1694
|
+
type IressFormProps,
|
|
971
1695
|
IressForm,
|
|
972
1696
|
IressModal,
|
|
973
1697
|
IressFormField,
|
|
@@ -1026,12 +1750,49 @@ export const FormSubmission \= () \=> {
|
|
|
1026
1750
|
);
|
|
1027
1751
|
};
|
|
1028
1752
|
|
|
1029
|
-
|
|
1753
|
+
```
|
|
1754
|
+
|
|
1755
|
+
#### Props
|
|
1756
|
+
|
|
1757
|
+
| Name | Description | Default | Control |
|
|
1758
|
+
| --- | --- | --- | --- |
|
|
1759
|
+
| alert |
|
|
1760
|
+
\-
|
|
1761
|
+
|
|
1762
|
+
| \- | Choose option...nonebasicAlert |
|
|
1763
|
+
| children |
|
|
1764
|
+
|
|
1765
|
+
object
|
|
1766
|
+
|
|
1767
|
+
|
|
1768
|
+
|
|
1769
|
+
| \- | \- |
|
|
1770
|
+
| form |
|
|
1771
|
+
|
|
1772
|
+
React hook form instance from `useForm`, use if you need more control over the internal state.
|
|
1773
|
+
|
|
1774
|
+
const form = useForm();
|
|
1775
|
+
return <IressForm form={form} />;
|
|
1776
|
+
|
|
1777
|
+
|
|
1778
|
+
UseFormReturn
|
|
1779
|
+
|
|
1780
|
+
|
|
1781
|
+
|
|
1782
|
+
| \- | Set object |
|
|
1783
|
+
| onSubmit |
|
|
1030
1784
|
|
|
1031
|
-
|
|
1785
|
+
\-
|
|
1786
|
+
|
|
1787
|
+
| \- | \- |
|
|
1788
|
+
| Show React Hook Forms itemsReact Hook Forms | Show React Hook Forms items |
|
|
1789
|
+
|
|
1790
|
+
### Read only
|
|
1032
1791
|
|
|
1033
1792
|
You can pass the `readOnly` prop to remove the asterisk symbol (\*) even when the field is `required`, and that field will be exempted from validation.
|
|
1034
1793
|
|
|
1794
|
+
[](./iframe.html?id=components-form--exclude-read-only-validation)
|
|
1795
|
+
|
|
1035
1796
|
Try hitting submit to see the validation summary: only email is being validated
|
|
1036
1797
|
-------------------------------------------------------------------------------
|
|
1037
1798
|
|
|
@@ -1043,14 +1804,12 @@ Luke Skywalker
|
|
|
1043
1804
|
|
|
1044
1805
|
Sign up
|
|
1045
1806
|
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
\[data-radix-scroll-area-viewport\] { scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; } \[data-radix-scroll-area-viewport\]::-webkit-scrollbar { display: none; } :where(\[data-radix-scroll-area-viewport\]) { display: flex; flex-direction: column; align-items: stretch; } :where(\[data-radix-scroll-area-content\]) { flex-grow: 1; }
|
|
1807
|
+
```
|
|
1049
1808
|
|
|
1050
1809
|
<IressStack gutter\="md"\>
|
|
1051
1810
|
<IressText element\="h2"\>
|
|
1052
1811
|
Try hitting submit to see the validation summary: only email is being validated </IressText\>
|
|
1053
|
-
<
|
|
1812
|
+
<ForwardedForm\>
|
|
1054
1813
|
<IressStack gutter\="md"\>
|
|
1055
1814
|
<IressFormField
|
|
1056
1815
|
label\="Name"
|
|
@@ -1079,13 +1838,43 @@ Hide code
|
|
|
1079
1838
|
\>
|
|
1080
1839
|
Sign up </IressButton\>
|
|
1081
1840
|
</IressStack\>
|
|
1082
|
-
</
|
|
1841
|
+
</ForwardedForm\>
|
|
1083
1842
|
</IressStack\>
|
|
1084
1843
|
|
|
1085
|
-
|
|
1844
|
+
```
|
|
1845
|
+
|
|
1846
|
+
#### Props
|
|
1847
|
+
|
|
1848
|
+
| Name | Description | Default | Control |
|
|
1849
|
+
| --- | --- | --- | --- |
|
|
1850
|
+
| alert |
|
|
1851
|
+
\-
|
|
1852
|
+
|
|
1853
|
+
| \- | Choose option...nonebasicAlert |
|
|
1854
|
+
| children |
|
|
1855
|
+
|
|
1856
|
+
object
|
|
1857
|
+
|
|
1858
|
+
|
|
1859
|
+
|
|
1860
|
+
| \- | Choose option...nonesimplesupportedControlsreadOnly |
|
|
1861
|
+
| form |
|
|
1086
1862
|
|
|
1087
|
-
|
|
1088
|
-
|
|
1863
|
+
React hook form instance from `useForm`, use if you need more control over the internal state.
|
|
1864
|
+
|
|
1865
|
+
const form = useForm();
|
|
1866
|
+
return <IressForm form={form} />;
|
|
1867
|
+
|
|
1868
|
+
|
|
1869
|
+
UseFormReturn
|
|
1870
|
+
|
|
1871
|
+
|
|
1872
|
+
|
|
1873
|
+
| \- | Set object |
|
|
1874
|
+
| Show React Hook Forms itemsReact Hook Forms | Show React Hook Forms items |
|
|
1875
|
+
|
|
1876
|
+
Behaviour
|
|
1877
|
+
---------
|
|
1089
1878
|
|
|
1090
1879
|
* Initial form validation is done when the user first submits the form. This allows them to focus on entering data without being overwhelmed by validation errors.
|
|
1091
1880
|
* If there are validation errors on submission, they will be shown at the form level as a summary, as well as per field. Only the first failing error will be displayed per field.
|
|
@@ -1093,13 +1882,15 @@ Copy
|
|
|
1093
1882
|
|
|
1094
1883
|
**Note:** The default user experience regarding validation is different to previous versions of IDS. This change was done to align IDS with the typical user experience found in other applications. If you would like to change the behaviour to be more consistent with the original IDS, set the `mode` prop of the form to `onBlur`.
|
|
1095
1884
|
|
|
1096
|
-
|
|
1097
|
-
|
|
1885
|
+
Examples
|
|
1886
|
+
--------
|
|
1098
1887
|
|
|
1099
|
-
###
|
|
1888
|
+
### Validation summary
|
|
1100
1889
|
|
|
1101
1890
|
If errors are present, they are displayed in a summary at the top of the page. This can be customised using the `errorSummaryHeading` prop.
|
|
1102
1891
|
|
|
1892
|
+
[](./iframe.html?id=components-form--validation-summary)
|
|
1893
|
+
|
|
1103
1894
|
Try hitting submit to see the validation summary
|
|
1104
1895
|
------------------------------------------------
|
|
1105
1896
|
|
|
@@ -1109,14 +1900,12 @@ Try hitting submit to see the validation summary
|
|
|
1109
1900
|
|
|
1110
1901
|
Sign up
|
|
1111
1902
|
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
\[data-radix-scroll-area-viewport\] { scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; } \[data-radix-scroll-area-viewport\]::-webkit-scrollbar { display: none; } :where(\[data-radix-scroll-area-viewport\]) { display: flex; flex-direction: column; align-items: stretch; } :where(\[data-radix-scroll-area-content\]) { flex-grow: 1; }
|
|
1903
|
+
```
|
|
1115
1904
|
|
|
1116
1905
|
<IressStack gutter\="md"\>
|
|
1117
1906
|
<IressText element\="h2"\>
|
|
1118
1907
|
Try hitting submit to see the validation summary </IressText\>
|
|
1119
|
-
<
|
|
1908
|
+
<ForwardedForm errorSummaryHeading\="We have seen the following errors in your submission..."\>
|
|
1120
1909
|
<IressStack gutter\="md"\>
|
|
1121
1910
|
<IressFormField
|
|
1122
1911
|
label\="Name"
|
|
@@ -1144,15 +1933,54 @@ Hide code
|
|
|
1144
1933
|
\>
|
|
1145
1934
|
Sign up </IressButton\>
|
|
1146
1935
|
</IressStack\>
|
|
1147
|
-
</
|
|
1936
|
+
</ForwardedForm\>
|
|
1148
1937
|
</IressStack\>
|
|
1149
1938
|
|
|
1150
|
-
|
|
1939
|
+
```
|
|
1940
|
+
|
|
1941
|
+
#### Props
|
|
1942
|
+
|
|
1943
|
+
| Name | Description | Default | Control |
|
|
1944
|
+
| --- | --- | --- | --- |
|
|
1945
|
+
| alert |
|
|
1946
|
+
\-
|
|
1151
1947
|
|
|
1152
|
-
|
|
1948
|
+
| \- | Choose option...nonebasicAlert |
|
|
1949
|
+
| children |
|
|
1950
|
+
|
|
1951
|
+
object
|
|
1952
|
+
|
|
1953
|
+
|
|
1954
|
+
|
|
1955
|
+
| \- | Choose option...nonesimplesupportedControlsreadOnly |
|
|
1956
|
+
| errorSummaryHeading |
|
|
1957
|
+
|
|
1958
|
+
string
|
|
1959
|
+
|
|
1960
|
+
|
|
1961
|
+
|
|
1962
|
+
| \- | We have seen the following errors in your submission... |
|
|
1963
|
+
| form |
|
|
1964
|
+
|
|
1965
|
+
React hook form instance from `useForm`, use if you need more control over the internal state.
|
|
1966
|
+
|
|
1967
|
+
const form = useForm();
|
|
1968
|
+
return <IressForm form={form} />;
|
|
1969
|
+
|
|
1970
|
+
|
|
1971
|
+
UseFormReturn
|
|
1972
|
+
|
|
1973
|
+
|
|
1974
|
+
|
|
1975
|
+
| \- | Set object |
|
|
1976
|
+
| Show React Hook Forms itemsReact Hook Forms | Show React Hook Forms items |
|
|
1977
|
+
|
|
1978
|
+
### Hidden validation summary
|
|
1153
1979
|
|
|
1154
1980
|
Use the `hiddenErrorSummary` prop to hide the summary altogether, and only show the errors on the fields. This is only recommended for short forms, for long forms it is recommended to keep the error summary shown for best accessibility.
|
|
1155
1981
|
|
|
1982
|
+
[](./iframe.html?id=components-form--hidden-error-summary)
|
|
1983
|
+
|
|
1156
1984
|
Try hitting submit to see the errors only on the fields
|
|
1157
1985
|
-------------------------------------------------------
|
|
1158
1986
|
|
|
@@ -1162,14 +1990,12 @@ Try hitting submit to see the errors only on the fields
|
|
|
1162
1990
|
|
|
1163
1991
|
Sign up
|
|
1164
1992
|
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
\[data-radix-scroll-area-viewport\] { scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; } \[data-radix-scroll-area-viewport\]::-webkit-scrollbar { display: none; } :where(\[data-radix-scroll-area-viewport\]) { display: flex; flex-direction: column; align-items: stretch; } :where(\[data-radix-scroll-area-content\]) { flex-grow: 1; }
|
|
1993
|
+
```
|
|
1168
1994
|
|
|
1169
1995
|
<IressStack gutter\="md"\>
|
|
1170
1996
|
<IressText element\="h2"\>
|
|
1171
1997
|
Try hitting submit to see the errors only on the fields </IressText\>
|
|
1172
|
-
<
|
|
1998
|
+
<ForwardedForm hiddenErrorSummary\>
|
|
1173
1999
|
<IressStack gutter\="md"\>
|
|
1174
2000
|
<IressFormField
|
|
1175
2001
|
label\="Name"
|
|
@@ -1197,30 +2023,67 @@ Hide code
|
|
|
1197
2023
|
\>
|
|
1198
2024
|
Sign up </IressButton\>
|
|
1199
2025
|
</IressStack\>
|
|
1200
|
-
</
|
|
2026
|
+
</ForwardedForm\>
|
|
1201
2027
|
</IressStack\>
|
|
1202
2028
|
|
|
1203
|
-
|
|
2029
|
+
```
|
|
2030
|
+
|
|
2031
|
+
#### Props
|
|
2032
|
+
|
|
2033
|
+
| Name | Description | Default | Control |
|
|
2034
|
+
| --- | --- | --- | --- |
|
|
2035
|
+
| alert |
|
|
2036
|
+
\-
|
|
2037
|
+
|
|
2038
|
+
| \- | Choose option...nonebasicAlert |
|
|
2039
|
+
| children |
|
|
2040
|
+
|
|
2041
|
+
object
|
|
2042
|
+
|
|
2043
|
+
|
|
2044
|
+
|
|
2045
|
+
| \- | Choose option...nonesimplesupportedControlsreadOnly |
|
|
2046
|
+
| form |
|
|
2047
|
+
|
|
2048
|
+
React hook form instance from `useForm`, use if you need more control over the internal state.
|
|
2049
|
+
|
|
2050
|
+
const form = useForm();
|
|
2051
|
+
return <IressForm form={form} />;
|
|
2052
|
+
|
|
2053
|
+
|
|
2054
|
+
UseFormReturn
|
|
2055
|
+
|
|
2056
|
+
|
|
2057
|
+
|
|
2058
|
+
| \- | Set object |
|
|
2059
|
+
| hiddenErrorSummary |
|
|
2060
|
+
|
|
2061
|
+
boolean
|
|
1204
2062
|
|
|
1205
|
-
|
|
2063
|
+
|
|
2064
|
+
|
|
2065
|
+
| \- | FalseTrue |
|
|
2066
|
+
| Show React Hook Forms itemsReact Hook Forms | Show React Hook Forms items |
|
|
2067
|
+
|
|
2068
|
+
### Custom error handling
|
|
1206
2069
|
|
|
1207
2070
|
The `onError` prop allows you to listen to any field errors. It takes two arguments. The first is a map of the field name and an object containing the first error message and type. The second is a ref to the original element that caused the error (the ref of the underlying input).
|
|
1208
2071
|
|
|
1209
2072
|
One use case for this prop is to create your own error summary.
|
|
1210
2073
|
|
|
2074
|
+
[](./iframe.html?id=components-form--custom-error-handling)
|
|
2075
|
+
|
|
1211
2076
|
\*Required Name
|
|
1212
2077
|
|
|
1213
2078
|
\*Required Email address
|
|
1214
2079
|
|
|
1215
2080
|
Sign up
|
|
1216
2081
|
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
\[data-radix-scroll-area-viewport\] { scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; } \[data-radix-scroll-area-viewport\]::-webkit-scrollbar { display: none; } :where(\[data-radix-scroll-area-viewport\]) { display: flex; flex-direction: column; align-items: stretch; } :where(\[data-radix-scroll-area-content\]) { flex-grow: 1; }
|
|
2082
|
+
```
|
|
1220
2083
|
|
|
1221
2084
|
import {
|
|
1222
2085
|
IressTable,
|
|
1223
|
-
IressFormProps,
|
|
2086
|
+
type IressFormProps,
|
|
1224
2087
|
IressForm,
|
|
1225
2088
|
IressModal,
|
|
1226
2089
|
IressStack,
|
|
@@ -1229,7 +2092,7 @@ import {
|
|
|
1229
2092
|
IressButton,
|
|
1230
2093
|
} from '@iress-oss/ids-components';
|
|
1231
2094
|
import { useState } from 'react';
|
|
1232
|
-
import { FieldErrors } from 'react-hook-form';
|
|
2095
|
+
import { type FieldErrors } from 'react-hook-form';
|
|
1233
2096
|
interface FieldValues {
|
|
1234
2097
|
name?: string;
|
|
1235
2098
|
email?: string;
|
|
@@ -1289,23 +2152,65 @@ export const CustomErrorHandlingForm \= () \=> {
|
|
|
1289
2152
|
);
|
|
1290
2153
|
};
|
|
1291
2154
|
|
|
1292
|
-
|
|
2155
|
+
```
|
|
2156
|
+
|
|
2157
|
+
#### Props
|
|
2158
|
+
|
|
2159
|
+
| Name | Description | Default | Control |
|
|
2160
|
+
| --- | --- | --- | --- |
|
|
2161
|
+
| alert |
|
|
2162
|
+
\-
|
|
2163
|
+
|
|
2164
|
+
| \- | Choose option...nonebasicAlert |
|
|
2165
|
+
| children |
|
|
2166
|
+
|
|
2167
|
+
object
|
|
2168
|
+
|
|
2169
|
+
|
|
2170
|
+
|
|
2171
|
+
| \- | \- |
|
|
2172
|
+
| form |
|
|
2173
|
+
|
|
2174
|
+
React hook form instance from `useForm`, use if you need more control over the internal state.
|
|
2175
|
+
|
|
2176
|
+
const form = useForm();
|
|
2177
|
+
return <IressForm form={form} />;
|
|
2178
|
+
|
|
2179
|
+
|
|
2180
|
+
UseFormReturn
|
|
2181
|
+
|
|
1293
2182
|
|
|
1294
|
-
|
|
2183
|
+
|
|
2184
|
+
| \- | Set object |
|
|
2185
|
+
| hiddenErrorSummary |
|
|
2186
|
+
|
|
2187
|
+
boolean
|
|
2188
|
+
|
|
2189
|
+
|
|
2190
|
+
|
|
2191
|
+
| \- | FalseTrue |
|
|
2192
|
+
| onError |
|
|
2193
|
+
|
|
2194
|
+
\-
|
|
2195
|
+
|
|
2196
|
+
| \- | \- |
|
|
2197
|
+
| Show React Hook Forms itemsReact Hook Forms | Show React Hook Forms items |
|
|
2198
|
+
|
|
2199
|
+
### Pre-fill the form
|
|
1295
2200
|
|
|
1296
2201
|
You can set the `defaultValues` prop to pre-fill the form values.
|
|
1297
2202
|
|
|
2203
|
+
[](./iframe.html?id=components-form--default-values)
|
|
2204
|
+
|
|
1298
2205
|
\*Required Name
|
|
1299
2206
|
|
|
1300
2207
|
\*Required Email address
|
|
1301
2208
|
|
|
1302
2209
|
Sign up
|
|
1303
2210
|
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
\[data-radix-scroll-area-viewport\] { scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; } \[data-radix-scroll-area-viewport\]::-webkit-scrollbar { display: none; } :where(\[data-radix-scroll-area-viewport\]) { display: flex; flex-direction: column; align-items: stretch; } :where(\[data-radix-scroll-area-content\]) { flex-grow: 1; }
|
|
2211
|
+
```
|
|
1307
2212
|
|
|
1308
|
-
<
|
|
2213
|
+
<ForwardedForm
|
|
1309
2214
|
defaultValues\={{
|
|
1310
2215
|
email: 'luke.skywalker@iress.com',
|
|
1311
2216
|
name: 'Luke Skywalker'
|
|
@@ -1338,11 +2243,41 @@ Hide code
|
|
|
1338
2243
|
\>
|
|
1339
2244
|
Sign up </IressButton\>
|
|
1340
2245
|
</IressStack\>
|
|
1341
|
-
</
|
|
2246
|
+
</ForwardedForm\>
|
|
2247
|
+
|
|
2248
|
+
```
|
|
2249
|
+
|
|
2250
|
+
#### Props
|
|
2251
|
+
|
|
2252
|
+
| Name | Description | Default | Control |
|
|
2253
|
+
| --- | --- | --- | --- |
|
|
2254
|
+
| alert |
|
|
2255
|
+
\-
|
|
2256
|
+
|
|
2257
|
+
| \- | Choose option...nonebasicAlert |
|
|
2258
|
+
| children |
|
|
2259
|
+
|
|
2260
|
+
object
|
|
2261
|
+
|
|
1342
2262
|
|
|
1343
|
-
Copy
|
|
1344
2263
|
|
|
1345
|
-
|
|
2264
|
+
| \- | Choose option...nonesimplesupportedControlsreadOnly |
|
|
2265
|
+
| form |
|
|
2266
|
+
|
|
2267
|
+
React hook form instance from `useForm`, use if you need more control over the internal state.
|
|
2268
|
+
|
|
2269
|
+
const form = useForm();
|
|
2270
|
+
return <IressForm form={form} />;
|
|
2271
|
+
|
|
2272
|
+
|
|
2273
|
+
UseFormReturn
|
|
2274
|
+
|
|
2275
|
+
|
|
2276
|
+
|
|
2277
|
+
| \- | Set object |
|
|
2278
|
+
| Show React Hook Forms itemsReact Hook Forms | Show React Hook Forms items |
|
|
2279
|
+
|
|
2280
|
+
### `values`
|
|
1346
2281
|
|
|
1347
2282
|
If you would like more control over each value of the form, you should use the `values` prop. This will make the form controlled, meaning it will rely completely on the `values` state to render the value of each field. You will need to use the `onSubmit` prop to sync the form value with your state.
|
|
1348
2283
|
|
|
@@ -1353,6 +2288,8 @@ Use cases where you may need the `values` prop:
|
|
|
1353
2288
|
|
|
1354
2289
|
**Note:** `values` takes precedence over `defaultValues`. To ensure your form state is predictable, it is best to only use one prop to manage form values.
|
|
1355
2290
|
|
|
2291
|
+
[](./iframe.html?id=components-form--values)
|
|
2292
|
+
|
|
1356
2293
|
\*Required Name
|
|
1357
2294
|
|
|
1358
2295
|
\*Required Email address
|
|
@@ -1363,9 +2300,7 @@ Sign up
|
|
|
1363
2300
|
|
|
1364
2301
|
Last updateClear
|
|
1365
2302
|
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
\[data-radix-scroll-area-viewport\] { scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; } \[data-radix-scroll-area-viewport\]::-webkit-scrollbar { display: none; } :where(\[data-radix-scroll-area-viewport\]) { display: flex; flex-direction: column; align-items: stretch; } :where(\[data-radix-scroll-area-content\]) { flex-grow: 1; }
|
|
2303
|
+
```
|
|
1369
2304
|
|
|
1370
2305
|
interface FieldValues {
|
|
1371
2306
|
name?: string;
|
|
@@ -1439,9 +2374,44 @@ export const ControlledForm \= (args: IressFormProps<FieldValues\>) \=> {
|
|
|
1439
2374
|
);
|
|
1440
2375
|
};
|
|
1441
2376
|
|
|
1442
|
-
|
|
2377
|
+
```
|
|
2378
|
+
|
|
2379
|
+
#### Props
|
|
2380
|
+
|
|
2381
|
+
| Name | Description | Default | Control |
|
|
2382
|
+
| --- | --- | --- | --- |
|
|
2383
|
+
| alert |
|
|
2384
|
+
\-
|
|
2385
|
+
|
|
2386
|
+
| \- | Choose option...nonebasicAlert |
|
|
2387
|
+
| children |
|
|
2388
|
+
|
|
2389
|
+
object
|
|
2390
|
+
|
|
2391
|
+
|
|
2392
|
+
|
|
2393
|
+
| \- | Choose option...nonesimplesupportedControlsreadOnly |
|
|
2394
|
+
| form |
|
|
1443
2395
|
|
|
1444
|
-
|
|
2396
|
+
React hook form instance from `useForm`, use if you need more control over the internal state.
|
|
2397
|
+
|
|
2398
|
+
const form = useForm();
|
|
2399
|
+
return <IressForm form={form} />;
|
|
2400
|
+
|
|
2401
|
+
|
|
2402
|
+
UseFormReturn
|
|
2403
|
+
|
|
2404
|
+
|
|
2405
|
+
|
|
2406
|
+
| \- | Set object |
|
|
2407
|
+
| onSubmit |
|
|
2408
|
+
|
|
2409
|
+
\-
|
|
2410
|
+
|
|
2411
|
+
| \- | \- |
|
|
2412
|
+
| Show React Hook Forms itemsReact Hook Forms | Show React Hook Forms items |
|
|
2413
|
+
|
|
2414
|
+
### Disable validation
|
|
1445
2415
|
|
|
1446
2416
|
Disabling validation is not possible with the `IressForm` component. In cases where you do need to disable validation, please consider the following:
|
|
1447
2417
|
|
|
@@ -1450,6 +2420,8 @@ Disabling validation is not possible with the `IressForm` component. In cases wh
|
|
|
1450
2420
|
|
|
1451
2421
|
Here we have an example showcasing option one.
|
|
1452
2422
|
|
|
2423
|
+
[](./iframe.html?id=components-form--disable-validation)
|
|
2424
|
+
|
|
1453
2425
|
\*Required Name
|
|
1454
2426
|
|
|
1455
2427
|
\*Required Email address
|
|
@@ -1460,17 +2432,15 @@ Sign up
|
|
|
1460
2432
|
|
|
1461
2433
|
Save as draft
|
|
1462
2434
|
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
\[data-radix-scroll-area-viewport\] { scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; } \[data-radix-scroll-area-viewport\]::-webkit-scrollbar { display: none; } :where(\[data-radix-scroll-area-viewport\]) { display: flex; flex-direction: column; align-items: stretch; } :where(\[data-radix-scroll-area-content\]) { flex-grow: 1; }
|
|
2435
|
+
```
|
|
1466
2436
|
|
|
1467
2437
|
import {
|
|
1468
|
-
FormRef,
|
|
2438
|
+
type FormRef,
|
|
1469
2439
|
IressButton,
|
|
1470
2440
|
IressDivider,
|
|
1471
2441
|
IressForm,
|
|
1472
2442
|
IressFormField,
|
|
1473
|
-
IressFormProps,
|
|
2443
|
+
type IressFormProps,
|
|
1474
2444
|
IressInput,
|
|
1475
2445
|
IressStack,
|
|
1476
2446
|
IressToasterProvider,
|
|
@@ -1546,14 +2516,56 @@ export const DisableValidationForm \= () \=> (
|
|
|
1546
2516
|
</IressToasterProvider\>
|
|
1547
2517
|
);
|
|
1548
2518
|
|
|
1549
|
-
|
|
2519
|
+
```
|
|
2520
|
+
|
|
2521
|
+
#### Props
|
|
2522
|
+
|
|
2523
|
+
| Name | Description | Default | Control |
|
|
2524
|
+
| --- | --- | --- | --- |
|
|
2525
|
+
| alert |
|
|
2526
|
+
\-
|
|
2527
|
+
|
|
2528
|
+
| \- | Choose option...nonebasicAlert |
|
|
2529
|
+
| children |
|
|
2530
|
+
|
|
2531
|
+
object
|
|
2532
|
+
|
|
2533
|
+
|
|
1550
2534
|
|
|
1551
|
-
|
|
2535
|
+
| \- | \- |
|
|
2536
|
+
| form |
|
|
2537
|
+
|
|
2538
|
+
React hook form instance from `useForm`, use if you need more control over the internal state.
|
|
2539
|
+
|
|
2540
|
+
const form = useForm();
|
|
2541
|
+
return <IressForm form={form} />;
|
|
2542
|
+
|
|
2543
|
+
|
|
2544
|
+
UseFormReturn
|
|
2545
|
+
|
|
2546
|
+
|
|
2547
|
+
|
|
2548
|
+
| \- | Set object |
|
|
2549
|
+
| onError |
|
|
2550
|
+
|
|
2551
|
+
\-
|
|
2552
|
+
|
|
2553
|
+
| \- | \- |
|
|
2554
|
+
| onSubmit |
|
|
2555
|
+
|
|
2556
|
+
\-
|
|
2557
|
+
|
|
2558
|
+
| \- | \- |
|
|
2559
|
+
| Show React Hook Forms itemsReact Hook Forms | Show React Hook Forms items |
|
|
2560
|
+
|
|
2561
|
+
### Resetting the form
|
|
1552
2562
|
|
|
1553
2563
|
You can reset the form using the `ref` of the form. You must provide a `defaultValues` prop that contains all the fields in the form to ensure it resets properly.
|
|
1554
2564
|
|
|
1555
2565
|
**Note:** `<button type="reset" />` does not work with `IressForm`. You need to add an `onClick` prop to the button and use the `ref.reset` method to reset the form.
|
|
1556
2566
|
|
|
2567
|
+
[](./iframe.html?id=components-form--reset-form)
|
|
2568
|
+
|
|
1557
2569
|
\*Required Name
|
|
1558
2570
|
|
|
1559
2571
|
\*Required Email address
|
|
@@ -1564,14 +2576,12 @@ Sign up
|
|
|
1564
2576
|
|
|
1565
2577
|
Reset
|
|
1566
2578
|
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
\[data-radix-scroll-area-viewport\] { scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; } \[data-radix-scroll-area-viewport\]::-webkit-scrollbar { display: none; } :where(\[data-radix-scroll-area-viewport\]) { display: flex; flex-direction: column; align-items: stretch; } :where(\[data-radix-scroll-area-content\]) { flex-grow: 1; }
|
|
2579
|
+
```
|
|
1570
2580
|
|
|
1571
2581
|
import {
|
|
1572
|
-
IressFormProps,
|
|
2582
|
+
type IressFormProps,
|
|
1573
2583
|
IressForm,
|
|
1574
|
-
FormRef,
|
|
2584
|
+
type FormRef,
|
|
1575
2585
|
IressDivider,
|
|
1576
2586
|
IressButton,
|
|
1577
2587
|
IressStack,
|
|
@@ -1623,9 +2633,39 @@ export const FormReset \= () \=> {
|
|
|
1623
2633
|
);
|
|
1624
2634
|
};
|
|
1625
2635
|
|
|
1626
|
-
|
|
2636
|
+
```
|
|
2637
|
+
|
|
2638
|
+
#### Props
|
|
2639
|
+
|
|
2640
|
+
| Name | Description | Default | Control |
|
|
2641
|
+
| --- | --- | --- | --- |
|
|
2642
|
+
| alert |
|
|
2643
|
+
\-
|
|
2644
|
+
|
|
2645
|
+
| \- | Choose option...nonebasicAlert |
|
|
2646
|
+
| children |
|
|
1627
2647
|
|
|
1628
|
-
|
|
2648
|
+
object
|
|
2649
|
+
|
|
2650
|
+
|
|
2651
|
+
|
|
2652
|
+
| \- | \- |
|
|
2653
|
+
| form |
|
|
2654
|
+
|
|
2655
|
+
React hook form instance from `useForm`, use if you need more control over the internal state.
|
|
2656
|
+
|
|
2657
|
+
const form = useForm();
|
|
2658
|
+
return <IressForm form={form} />;
|
|
2659
|
+
|
|
2660
|
+
|
|
2661
|
+
UseFormReturn
|
|
2662
|
+
|
|
2663
|
+
|
|
2664
|
+
|
|
2665
|
+
| \- | Set object |
|
|
2666
|
+
| Show React Hook Forms itemsReact Hook Forms | Show React Hook Forms items |
|
|
2667
|
+
|
|
2668
|
+
### Custom form field components
|
|
1629
2669
|
|
|
1630
2670
|
You can integrate custom components within `IressFormField` to create enhanced form experiences.
|
|
1631
2671
|
|
|
@@ -1644,6 +2684,8 @@ Key features demonstrated:
|
|
|
1644
2684
|
* **Form State Management**: Automatically integrates with form context using controlled props
|
|
1645
2685
|
* **File Management**: Display uploaded files with remove functionality using `IressPanel`
|
|
1646
2686
|
|
|
2687
|
+
[](./iframe.html?id=components-form--custom-form-field-components)
|
|
2688
|
+
|
|
1647
2689
|
Custom FormField Components
|
|
1648
2690
|
===========================
|
|
1649
2691
|
|
|
@@ -1657,9 +2699,7 @@ Upload
|
|
|
1657
2699
|
|
|
1658
2700
|
Submit
|
|
1659
2701
|
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
\[data-radix-scroll-area-viewport\] { scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; } \[data-radix-scroll-area-viewport\]::-webkit-scrollbar { display: none; } :where(\[data-radix-scroll-area-viewport\]) { display: flex; flex-direction: column; align-items: stretch; } :where(\[data-radix-scroll-area-content\]) { flex-grow: 1; }
|
|
2702
|
+
```
|
|
1663
2703
|
|
|
1664
2704
|
import React, { useState } from 'react';
|
|
1665
2705
|
|
|
@@ -1768,7 +2808,7 @@ const TranscriptTextBox \= ({
|
|
|
1768
2808
|
reader.readAsText(file);
|
|
1769
2809
|
};
|
|
1770
2810
|
const handleTextChange \= (
|
|
1771
|
-
|
|
2811
|
+
\_e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement\>,
|
|
1772
2812
|
textContent: string,
|
|
1773
2813
|
) \=> {
|
|
1774
2814
|
onChange(createTranscriptData(textContent, 'text'));
|
|
@@ -1950,25 +2990,55 @@ export const CustomFormFieldComponents \= (
|
|
|
1950
2990
|
);
|
|
1951
2991
|
};
|
|
1952
2992
|
|
|
1953
|
-
|
|
2993
|
+
```
|
|
2994
|
+
|
|
2995
|
+
#### Props
|
|
2996
|
+
|
|
2997
|
+
| Name | Description | Default | Control |
|
|
2998
|
+
| --- | --- | --- | --- |
|
|
2999
|
+
| alert |
|
|
3000
|
+
\-
|
|
3001
|
+
|
|
3002
|
+
| \- | Choose option...nonebasicAlert |
|
|
3003
|
+
| children |
|
|
3004
|
+
|
|
3005
|
+
object
|
|
1954
3006
|
|
|
1955
|
-
|
|
3007
|
+
|
|
3008
|
+
|
|
3009
|
+
| \- | \- |
|
|
3010
|
+
| form |
|
|
3011
|
+
|
|
3012
|
+
React hook form instance from `useForm`, use if you need more control over the internal state.
|
|
3013
|
+
|
|
3014
|
+
const form = useForm();
|
|
3015
|
+
return <IressForm form={form} />;
|
|
3016
|
+
|
|
3017
|
+
|
|
3018
|
+
UseFormReturn
|
|
3019
|
+
|
|
3020
|
+
|
|
3021
|
+
|
|
3022
|
+
| \- | \- |
|
|
3023
|
+
| Show React Hook Forms itemsReact Hook Forms | Show React Hook Forms items |
|
|
3024
|
+
|
|
3025
|
+
### Forms in expanders (lazy loading)
|
|
1956
3026
|
|
|
1957
3027
|
If you are using forms in expanders, or in other scenarios when the loading of the form may be delayed, it is recommended to only load the form when it is required. This will improve performance of your application, and make it more predictable. It may also fix act warnings in tests if you are seeing some appearing due to conditionally loaded `IressForm` elements.
|
|
1958
3028
|
|
|
3029
|
+
[](./iframe.html?id=components-form--forms-in-expanders)
|
|
3030
|
+
|
|
1959
3031
|
Sender
|
|
1960
3032
|
|
|
1961
3033
|
Recipient
|
|
1962
3034
|
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
\[data-radix-scroll-area-viewport\] { scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; } \[data-radix-scroll-area-viewport\]::-webkit-scrollbar { display: none; } :where(\[data-radix-scroll-area-viewport\]) { display: flex; flex-direction: column; align-items: stretch; } :where(\[data-radix-scroll-area-content\]) { flex-grow: 1; }
|
|
3035
|
+
```
|
|
1966
3036
|
|
|
1967
3037
|
import {
|
|
1968
3038
|
IressExpander,
|
|
1969
3039
|
IressForm,
|
|
1970
3040
|
IressFormField,
|
|
1971
|
-
IressFormProps,
|
|
3041
|
+
type IressFormProps,
|
|
1972
3042
|
IressInput,
|
|
1973
3043
|
IressStack,
|
|
1974
3044
|
} from '@iress-oss/ids-components';
|
|
@@ -2026,9 +3096,39 @@ export const FormExpanders \= () \=> {
|
|
|
2026
3096
|
);
|
|
2027
3097
|
};
|
|
2028
3098
|
|
|
2029
|
-
|
|
3099
|
+
```
|
|
3100
|
+
|
|
3101
|
+
#### Props
|
|
3102
|
+
|
|
3103
|
+
| Name | Description | Default | Control |
|
|
3104
|
+
| --- | --- | --- | --- |
|
|
3105
|
+
| alert |
|
|
3106
|
+
\-
|
|
3107
|
+
|
|
3108
|
+
| \- | Choose option...nonebasicAlert |
|
|
3109
|
+
| children |
|
|
3110
|
+
|
|
3111
|
+
object
|
|
3112
|
+
|
|
2030
3113
|
|
|
2031
|
-
|
|
3114
|
+
|
|
3115
|
+
| \- | \- |
|
|
3116
|
+
| form |
|
|
3117
|
+
|
|
3118
|
+
React hook form instance from `useForm`, use if you need more control over the internal state.
|
|
3119
|
+
|
|
3120
|
+
const form = useForm();
|
|
3121
|
+
return <IressForm form={form} />;
|
|
3122
|
+
|
|
3123
|
+
|
|
3124
|
+
UseFormReturn
|
|
3125
|
+
|
|
3126
|
+
|
|
3127
|
+
|
|
3128
|
+
| \- | Set object |
|
|
3129
|
+
| Show React Hook Forms itemsReact Hook Forms | Show React Hook Forms items |
|
|
3130
|
+
|
|
3131
|
+
### Conditional fields (useWatch)
|
|
2032
3132
|
|
|
2033
3133
|
When you have fields that are conditionally shown, you can use the `IressForm.useWatch` hook to watch the value of another field and conditionally render the field.
|
|
2034
3134
|
|
|
@@ -2036,6 +3136,8 @@ When you have fields that are conditionally shown, you can use the `IressForm.us
|
|
|
2036
3136
|
|
|
2037
3137
|
* You can use the `api.watch` method on the `IressForm`'s ref to watch the value of a field, but it is recommended to use the hook for better performance by isolating re-rendering at the component level.
|
|
2038
3138
|
|
|
3139
|
+
[](./iframe.html?id=components-form--use-watch)
|
|
3140
|
+
|
|
2039
3141
|
This is a conditional field example using "useWatch".
|
|
2040
3142
|
|
|
2041
3143
|
\*Required Select fields to show
|
|
@@ -2048,9 +3150,7 @@ Email
|
|
|
2048
3150
|
|
|
2049
3151
|
Submit
|
|
2050
3152
|
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
\[data-radix-scroll-area-viewport\] { scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; } \[data-radix-scroll-area-viewport\]::-webkit-scrollbar { display: none; } :where(\[data-radix-scroll-area-viewport\]) { display: flex; flex-direction: column; align-items: stretch; } :where(\[data-radix-scroll-area-content\]) { flex-grow: 1; }
|
|
3153
|
+
```
|
|
2054
3154
|
|
|
2055
3155
|
import {
|
|
2056
3156
|
IressButton,
|
|
@@ -2059,7 +3159,7 @@ import {
|
|
|
2059
3159
|
IressDivider,
|
|
2060
3160
|
IressForm,
|
|
2061
3161
|
IressFormField,
|
|
2062
|
-
IressFormProps,
|
|
3162
|
+
type IressFormProps,
|
|
2063
3163
|
IressInput,
|
|
2064
3164
|
IressStack,
|
|
2065
3165
|
IressText,
|
|
@@ -2129,10 +3229,40 @@ export const UseWatchForm \= () \=> (
|
|
|
2129
3229
|
</IressForm\>
|
|
2130
3230
|
);
|
|
2131
3231
|
|
|
2132
|
-
|
|
3232
|
+
```
|
|
3233
|
+
|
|
3234
|
+
#### Props
|
|
3235
|
+
|
|
3236
|
+
| Name | Description | Default | Control |
|
|
3237
|
+
| --- | --- | --- | --- |
|
|
3238
|
+
| alert |
|
|
3239
|
+
\-
|
|
3240
|
+
|
|
3241
|
+
| \- | Choose option...nonebasicAlert |
|
|
3242
|
+
| children |
|
|
3243
|
+
|
|
3244
|
+
object
|
|
3245
|
+
|
|
3246
|
+
|
|
2133
3247
|
|
|
2134
|
-
|
|
2135
|
-
|
|
3248
|
+
| \- | Choose option...nonesimplesupportedControlsreadOnly |
|
|
3249
|
+
| form |
|
|
3250
|
+
|
|
3251
|
+
React hook form instance from `useForm`, use if you need more control over the internal state.
|
|
3252
|
+
|
|
3253
|
+
const form = useForm();
|
|
3254
|
+
return <IressForm form={form} />;
|
|
3255
|
+
|
|
3256
|
+
|
|
3257
|
+
UseFormReturn
|
|
3258
|
+
|
|
3259
|
+
|
|
3260
|
+
|
|
3261
|
+
| \- | Set object |
|
|
3262
|
+
| Show React Hook Forms itemsReact Hook Forms | Show React Hook Forms items |
|
|
3263
|
+
|
|
3264
|
+
`IressHookForm`
|
|
3265
|
+
---------------
|
|
2136
3266
|
|
|
2137
3267
|
`IressHookForm` is the underlying component that `IressForm` is built upon. It has a single required prop, `form`, which expects the return value of the `useForm` hook from React Hook Forms.
|
|
2138
3268
|
|
|
@@ -2143,15 +3273,15 @@ Some use cases:
|
|
|
2143
3273
|
1. You may need to use the `useForm` hook in a parent component to share the form state with multiple child components.
|
|
2144
3274
|
2. You would like to use the return value of the `useForm` hook without having to use a ref to access the `react-hook-form` api.
|
|
2145
3275
|
|
|
3276
|
+
[](./iframe.html?id=components-form--hook-form)
|
|
3277
|
+
|
|
2146
3278
|
\*Required First Name
|
|
2147
3279
|
|
|
2148
3280
|
\*Required Last Name
|
|
2149
3281
|
|
|
2150
3282
|
Submit
|
|
2151
3283
|
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
\[data-radix-scroll-area-viewport\] { scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; } \[data-radix-scroll-area-viewport\]::-webkit-scrollbar { display: none; } :where(\[data-radix-scroll-area-viewport\]) { display: flex; flex-direction: column; align-items: stretch; } :where(\[data-radix-scroll-area-content\]) { flex-grow: 1; }
|
|
3284
|
+
```
|
|
2155
3285
|
|
|
2156
3286
|
interface FieldValues {
|
|
2157
3287
|
firstName: string;
|
|
@@ -2190,10 +3320,128 @@ export const HookFormExample \= () \=> {
|
|
|
2190
3320
|
);
|
|
2191
3321
|
};
|
|
2192
3322
|
|
|
2193
|
-
|
|
3323
|
+
```
|
|
3324
|
+
|
|
3325
|
+
#### Props
|
|
3326
|
+
|
|
3327
|
+
| Name | Description | Default | Control |
|
|
3328
|
+
| --- | --- | --- | --- |
|
|
3329
|
+
| alert |
|
|
3330
|
+
Section to place error summary when the app is in control of validation.
|
|
3331
|
+
|
|
3332
|
+
ReactReactNode
|
|
3333
|
+
|
|
3334
|
+
|
|
3335
|
+
|
|
3336
|
+
| \- | Set object |
|
|
3337
|
+
| children |
|
|
3338
|
+
|
|
3339
|
+
The content of the form, usually multiple `IressFormField` or `IressFormFieldset` components.
|
|
3340
|
+
|
|
3341
|
+
ReactReactNode
|
|
3342
|
+
|
|
3343
|
+
|
|
3344
|
+
|
|
3345
|
+
| \- | Set object |
|
|
3346
|
+
| errorSummaryHeading |
|
|
3347
|
+
|
|
3348
|
+
Content to be displayed in the title of the error summary.
|
|
3349
|
+
|
|
3350
|
+
ReactNode
|
|
3351
|
+
|
|
3352
|
+
|
|
3353
|
+
|
|
3354
|
+
| <h3>There was a problem submitting this form</h3> | Set object |
|
|
3355
|
+
| errorSummaryHeadingLevel |
|
|
3356
|
+
|
|
3357
|
+
Level of error summary heading for semantics.
|
|
3358
|
+
|
|
3359
|
+
HeadingLevel
|
|
3360
|
+
|
|
3361
|
+
<table class="css-3nr4py"><tbody><tr><td colspan="2"><strong>Deprecated</strong>: Use errorSummaryHeading instead.</td></tr></tbody></table>
|
|
3362
|
+
|
|
3363
|
+
| \- | Set object |
|
|
3364
|
+
| errorSummaryHeadingText |
|
|
3365
|
+
|
|
3366
|
+
Text to be displayed in the title of the error summary.
|
|
3367
|
+
|
|
3368
|
+
string
|
|
2194
3369
|
|
|
2195
|
-
|
|
2196
|
-
|
|
3370
|
+
<table class="css-3nr4py"><tbody><tr><td colspan="2"><strong>Deprecated</strong>: Use errorSummaryHeading instead.</td></tr></tbody></table>
|
|
3371
|
+
|
|
3372
|
+
| \- | Set string |
|
|
3373
|
+
| form\* |
|
|
3374
|
+
|
|
3375
|
+
React hook form instance.
|
|
3376
|
+
|
|
3377
|
+
UseFormReturn
|
|
3378
|
+
|
|
3379
|
+
|
|
3380
|
+
|
|
3381
|
+
| \- | Set object |
|
|
3382
|
+
| gutter |
|
|
3383
|
+
|
|
3384
|
+
Sets the amount of spacing between the heading, alert, children and footer.
|
|
3385
|
+
|
|
3386
|
+
union
|
|
3387
|
+
|
|
3388
|
+
|
|
3389
|
+
|
|
3390
|
+
|
|
|
3391
|
+
|
|
3392
|
+
'lg'
|
|
3393
|
+
|
|
3394
|
+
| Set object |
|
|
3395
|
+
| hiddenErrorSummary |
|
|
3396
|
+
|
|
3397
|
+
Sets which of the block / inline layout options apply.
|
|
3398
|
+
|
|
3399
|
+
boolean
|
|
3400
|
+
|
|
3401
|
+
|
|
3402
|
+
|
|
3403
|
+
| \- | Set boolean |
|
|
3404
|
+
| onError |
|
|
3405
|
+
|
|
3406
|
+
Emitted when any field has an error. Called after the first submit if any errors are recorded, and from then on when any value changes.
|
|
3407
|
+
|
|
3408
|
+
[Learn more](https://react-hook-form.com/docs/useform/handlesubmit)
|
|
3409
|
+
|
|
3410
|
+
SubmitErrorHandler
|
|
3411
|
+
|
|
3412
|
+
|
|
3413
|
+
|
|
3414
|
+
| \- | Set object |
|
|
3415
|
+
| onSubmit |
|
|
3416
|
+
|
|
3417
|
+
Handler for when the submit method on the form is called after validation is passed.
|
|
3418
|
+
|
|
3419
|
+
[Learn more](https://react-hook-form.com/docs/useform/handlesubmit)
|
|
3420
|
+
|
|
3421
|
+
(data: T) => void
|
|
3422
|
+
|
|
3423
|
+
| \- | \- |
|
|
3424
|
+
| onValidChange |
|
|
3425
|
+
|
|
3426
|
+
Emitted when the form state is valid.
|
|
3427
|
+
|
|
3428
|
+
[Learn more](https://react-hook-form.com/docs/useform/formstate)
|
|
3429
|
+
|
|
3430
|
+
(isValid: boolean) => void
|
|
3431
|
+
|
|
3432
|
+
| \- | \- |
|
|
3433
|
+
| updateErrorSummaryOnSubmit |
|
|
3434
|
+
|
|
3435
|
+
If set to `true`, the summary will only update when the form is submitted, not on every field change. This is useful for performance reasons, especially in large forms.
|
|
3436
|
+
|
|
3437
|
+
boolean
|
|
3438
|
+
|
|
3439
|
+
|
|
3440
|
+
|
|
3441
|
+
| \- | Set boolean |
|
|
3442
|
+
|
|
3443
|
+
Migration to version 5
|
|
3444
|
+
----------------------
|
|
2197
3445
|
|
|
2198
3446
|
The previous form components contained a lot of logic to translate the HTML5 validation API to a format that matched the design system’s guidelines. This allowed users to use the default props of input such as `pattern` and `required`, and be assured that the `IressField` would display errors accordingly.
|
|
2199
3447
|
|
|
@@ -2205,30 +3453,13 @@ The validation logic has been stripped from all of the existing form components.
|
|
|
2205
3453
|
|
|
2206
3454
|
Automated validation is now solely contained in `IressForm` and `IressFormField`, using [React Hook Form](https://react-hook-form.com/docs/useform) under the hood to simplify maintenance.
|
|
2207
3455
|
|
|
2208
|
-
|
|
2209
|
-
|
|
3456
|
+
Testing
|
|
3457
|
+
-------
|
|
2210
3458
|
|
|
2211
3459
|
Unfortunately due to the asynchronous nature of React Hook Form validation, `IressForm` still needs to be tested using `screen.findBy` queries (at least in the first query after render). If `findBy` is not used, you will start to see the dreaded `act warnings`. For more information on testing IressForm, please refer to the (React Hook Form testing documentation)\[[https://react-hook-form.com/advanced-usage#TestingForm](https://react-hook-form.com/advanced-usage#TestingForm)\]
|
|
2212
3460
|
|
|
2213
3461
|
Here is an example of testing a form submission.
|
|
2214
3462
|
|
|
2215
|
-
\[data-radix-scroll-area-viewport\] {
|
|
2216
|
-
scrollbar-width: none;
|
|
2217
|
-
-ms-overflow-style: none;
|
|
2218
|
-
-webkit-overflow-scrolling: touch;
|
|
2219
|
-
}
|
|
2220
|
-
\[data-radix-scroll-area-viewport\]::-webkit-scrollbar {
|
|
2221
|
-
display: none;
|
|
2222
|
-
}
|
|
2223
|
-
:where(\[data-radix-scroll-area-viewport\]) {
|
|
2224
|
-
display: flex;
|
|
2225
|
-
flex-direction: column;
|
|
2226
|
-
align-items: stretch;
|
|
2227
|
-
}
|
|
2228
|
-
:where(\[data-radix-scroll-area-content\]) {
|
|
2229
|
-
flex-grow: 1;
|
|
2230
|
-
}
|
|
2231
|
-
|
|
2232
3463
|
render(
|
|
2233
3464
|
<IressForm\>
|
|
2234
3465
|
<IressFormField
|
|
@@ -2253,34 +3484,17 @@ const summaryError \= await screen.findByText(
|
|
|
2253
3484
|
);
|
|
2254
3485
|
expect(summaryError).toBeInTheDocument();
|
|
2255
3486
|
|
|
2256
|
-
|
|
3487
|
+
```
|
|
2257
3488
|
|
|
2258
|
-
|
|
2259
|
-
|
|
3489
|
+
Caveat
|
|
3490
|
+
------
|
|
2260
3491
|
|
|
2261
|
-
###
|
|
3492
|
+
### Using `IressSelect` with non-string values in `IressFormField`
|
|
2262
3493
|
|
|
2263
3494
|
When using form controls that support non-string values (like `IressSelect` with number values), you might encounter type conflicts with React Hook Form's default event handling. By default, React Hook Form expects string values from form controls.
|
|
2264
3495
|
|
|
2265
3496
|
**Problem:**
|
|
2266
3497
|
|
|
2267
|
-
\[data-radix-scroll-area-viewport\] {
|
|
2268
|
-
scrollbar-width: none;
|
|
2269
|
-
-ms-overflow-style: none;
|
|
2270
|
-
-webkit-overflow-scrolling: touch;
|
|
2271
|
-
}
|
|
2272
|
-
\[data-radix-scroll-area-viewport\]::-webkit-scrollbar {
|
|
2273
|
-
display: none;
|
|
2274
|
-
}
|
|
2275
|
-
:where(\[data-radix-scroll-area-viewport\]) {
|
|
2276
|
-
display: flex;
|
|
2277
|
-
flex-direction: column;
|
|
2278
|
-
align-items: stretch;
|
|
2279
|
-
}
|
|
2280
|
-
:where(\[data-radix-scroll-area-content\]) {
|
|
2281
|
-
flex-grow: 1;
|
|
2282
|
-
}
|
|
2283
|
-
|
|
2284
3498
|
<IressFormField
|
|
2285
3499
|
name\="dependents"
|
|
2286
3500
|
label\="Dependents"
|
|
@@ -2296,29 +3510,12 @@ When using form controls that support non-string values (like `IressSelect` with
|
|
|
2296
3510
|
)}
|
|
2297
3511
|
/>
|
|
2298
3512
|
|
|
2299
|
-
|
|
3513
|
+
```
|
|
2300
3514
|
|
|
2301
3515
|
In this case, React Hook Form will try to convert the value to string, which might cause type issues.
|
|
2302
3516
|
|
|
2303
3517
|
**Solution:** Override the `onChange` handler to pass the actual value as a second parameter:
|
|
2304
3518
|
|
|
2305
|
-
\[data-radix-scroll-area-viewport\] {
|
|
2306
|
-
scrollbar-width: none;
|
|
2307
|
-
-ms-overflow-style: none;
|
|
2308
|
-
-webkit-overflow-scrolling: touch;
|
|
2309
|
-
}
|
|
2310
|
-
\[data-radix-scroll-area-viewport\]::-webkit-scrollbar {
|
|
2311
|
-
display: none;
|
|
2312
|
-
}
|
|
2313
|
-
:where(\[data-radix-scroll-area-viewport\]) {
|
|
2314
|
-
display: flex;
|
|
2315
|
-
flex-direction: column;
|
|
2316
|
-
align-items: stretch;
|
|
2317
|
-
}
|
|
2318
|
-
:where(\[data-radix-scroll-area-content\]) {
|
|
2319
|
-
flex-grow: 1;
|
|
2320
|
-
}
|
|
2321
|
-
|
|
2322
3519
|
<IressFormField
|
|
2323
3520
|
name\="dependents"
|
|
2324
3521
|
label\="Dependents"
|
|
@@ -2337,106 +3534,39 @@ In this case, React Hook Form will try to convert the value to string, which mig
|
|
|
2337
3534
|
)}
|
|
2338
3535
|
/>
|
|
2339
3536
|
|
|
2340
|
-
|
|
3537
|
+
```
|
|
2341
3538
|
|
|
2342
3539
|
This ensures the original value type is preserved when passed to React Hook Form. You can find out more about the code example in the [Switch Edit Readonly Form Documentation](?path=/docs/components-form-recipes--docs#switching-between-readonly-and-edit-modes).
|
|
2343
3540
|
|
|
2344
|
-
###
|
|
3541
|
+
### Properly resetting fields
|
|
2345
3542
|
|
|
2346
3543
|
When resetting fields that accept non-string values (like `IressRichSelect`), you should reset them to `null` or `undefined` instead of an empty string. This is because the underlying component is strictly typed and expects a specific value type.
|
|
2347
3544
|
|
|
2348
3545
|
**Problem:**
|
|
2349
3546
|
|
|
2350
|
-
\[data-radix-scroll-area-viewport\] {
|
|
2351
|
-
scrollbar-width: none;
|
|
2352
|
-
-ms-overflow-style: none;
|
|
2353
|
-
-webkit-overflow-scrolling: touch;
|
|
2354
|
-
}
|
|
2355
|
-
\[data-radix-scroll-area-viewport\]::-webkit-scrollbar {
|
|
2356
|
-
display: none;
|
|
2357
|
-
}
|
|
2358
|
-
:where(\[data-radix-scroll-area-viewport\]) {
|
|
2359
|
-
display: flex;
|
|
2360
|
-
flex-direction: column;
|
|
2361
|
-
align-items: stretch;
|
|
2362
|
-
}
|
|
2363
|
-
:where(\[data-radix-scroll-area-content\]) {
|
|
2364
|
-
flex-grow: 1;
|
|
2365
|
-
}
|
|
2366
|
-
|
|
2367
3547
|
const { resetField } \= IressForm.useFormContext();
|
|
2368
3548
|
resetField('rich-select', {
|
|
2369
3549
|
label: '',
|
|
2370
3550
|
value: '',
|
|
2371
3551
|
});
|
|
2372
3552
|
|
|
2373
|
-
|
|
3553
|
+
```
|
|
2374
3554
|
|
|
2375
3555
|
In this case, it will look like it cleared the field, but actually it has not. This is obvious with a `placeholder` set, as it will not show the placeholder.
|
|
2376
3556
|
|
|
2377
3557
|
**Solution:** Override the `onChange` handler to pass the actual value as a second parameter:
|
|
2378
3558
|
|
|
2379
|
-
\[data-radix-scroll-area-viewport\] {
|
|
2380
|
-
scrollbar-width: none;
|
|
2381
|
-
-ms-overflow-style: none;
|
|
2382
|
-
-webkit-overflow-scrolling: touch;
|
|
2383
|
-
}
|
|
2384
|
-
\[data-radix-scroll-area-viewport\]::-webkit-scrollbar {
|
|
2385
|
-
display: none;
|
|
2386
|
-
}
|
|
2387
|
-
:where(\[data-radix-scroll-area-viewport\]) {
|
|
2388
|
-
display: flex;
|
|
2389
|
-
flex-direction: column;
|
|
2390
|
-
align-items: stretch;
|
|
2391
|
-
}
|
|
2392
|
-
:where(\[data-radix-scroll-area-content\]) {
|
|
2393
|
-
flex-grow: 1;
|
|
2394
|
-
}
|
|
2395
|
-
|
|
2396
3559
|
const { resetField } \= IressForm.useFormContext();
|
|
2397
3560
|
resetField('rich-select', null); // or undefined
|
|
2398
3561
|
|
|
2399
|
-
|
|
3562
|
+
```
|
|
2400
3563
|
|
|
2401
3564
|
This will properly reset the field to null and clear the field value.
|
|
2402
3565
|
|
|
2403
|
-
###
|
|
3566
|
+
### Conflicting versions of React Hook Forms
|
|
2404
3567
|
|
|
2405
3568
|
If you are using React Hook Forms in your application, please ensure it is the same version IDS uses, otherwise there will be conflicts.
|
|
2406
3569
|
|
|
2407
3570
|
The version we are using in IDS is:
|
|
2408
3571
|
|
|
2409
3572
|
yarn add react-hook-form@7.53.1
|
|
2410
|
-
|
|
2411
|
-
On this page
|
|
2412
|
-
|
|
2413
|
-
* [Overview](#overview)
|
|
2414
|
-
* [Props](#props)
|
|
2415
|
-
* [Key concepts](#key-concepts)
|
|
2416
|
-
* [State management](#state-management)
|
|
2417
|
-
* [Validation](#validation)
|
|
2418
|
-
* [Syncing state](#syncing-state)
|
|
2419
|
-
* [Usage](#usage)
|
|
2420
|
-
* [Fields](#fields)
|
|
2421
|
-
* [Rules](#rules)
|
|
2422
|
-
* [Handling submission](#handling-submission)
|
|
2423
|
-
* [Read only](#read-only)
|
|
2424
|
-
* [Behaviour](#behaviour)
|
|
2425
|
-
* [Examples](#examples)
|
|
2426
|
-
* [Validation summary](#validation-summary)
|
|
2427
|
-
* [Hidden validation summary](#hidden-validation-summary)
|
|
2428
|
-
* [Custom error handling](#custom-error-handling)
|
|
2429
|
-
* [Pre-fill the form](#pre-fill-the-form)
|
|
2430
|
-
* [values](#values)
|
|
2431
|
-
* [Disable validation](#disable-validation)
|
|
2432
|
-
* [Resetting the form](#resetting-the-form)
|
|
2433
|
-
* [Custom form field components](#custom-form-field-components)
|
|
2434
|
-
* [Forms in expanders (lazy loading)](#forms-in-expanders-lazy-loading)
|
|
2435
|
-
* [Conditional fields (useWatch)](#conditional-fields-usewatch)
|
|
2436
|
-
* [IressHookForm](#iresshookform)
|
|
2437
|
-
* [Migration to version 5](#migration-to-version-5)
|
|
2438
|
-
* [Testing](#testing)
|
|
2439
|
-
* [Caveat](#caveat)
|
|
2440
|
-
* [Using IressSelect with non-string values in IressFormField](#using-iressselect-with-non-string-values-in-iressformfield)
|
|
2441
|
-
* [Properly resetting fields](#properly-resetting-fields)
|
|
2442
|
-
* [Conflicting versions of React Hook Forms](#conflicting-versions-of-react-hook-forms)
|