@tsed/react-formio 1.10.9 → 1.10.13
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/.eslintrc +7 -2
- package/dist/components/form/form.component.d.ts +2 -44
- package/dist/components/form/useForm.hook.d.ts +56 -1
- package/dist/components/form-action/formAction.component.d.ts +1 -1
- package/dist/components/form-edit/formEdit.component.d.ts +4 -15
- package/dist/components/form-edit/useFormEdit.hook.d.ts +29 -0
- package/dist/index.js +47 -13323
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +35 -13143
- package/dist/index.modern.js.map +1 -1
- package/package.json +13 -12
- package/readme.md +81 -55
- package/src/components/actions-table/actionsTable.component.spec.tsx +15 -17
- package/src/components/actions-table/actionsTable.component.tsx +1 -0
- package/src/components/card/card.component.spec.tsx +2 -2
- package/src/components/card/card.component.tsx +2 -4
- package/src/components/form/form.component.tsx +3 -47
- package/src/components/form/useForm.hook.ts +62 -8
- package/src/components/form-access/formAccess.component.tsx +2 -1
- package/src/components/form-action/formAction.component.tsx +1 -1
- package/src/components/form-builder/formBuilder.component.tsx +2 -0
- package/src/components/form-edit/formEdit.component.tsx +5 -11
- package/src/components/form-edit/{useForm.hook.ts → useFormEdit.hook.ts} +8 -14
- package/src/components/form-settings/formSettings.component.tsx +3 -1
- package/src/components/forms-table/components/formCell.component.tsx +2 -2
- package/src/components/input-text/inputText.component.tsx +1 -1
- package/src/components/loader/loader.component.spec.tsx +2 -2
- package/src/components/loader/loader.component.tsx +1 -1
- package/src/components/modal/modal.component.spec.tsx +3 -3
- package/src/components/modal/modal.component.tsx +6 -1
- package/src/components/modal/modal.stories.tsx +5 -21
- package/src/components/react-component/reactComponent.component.tsx +1 -0
- package/src/components/select/select.component.tsx +1 -1
- package/src/components/table/components/defaultOperationButton.component.tsx +2 -2
- package/src/components/table/filters/defaultColumnFilter.component.spec.tsx +2 -2
- package/src/components/table/table.component.tsx +16 -5
- package/src/components/tabs/tabs.component.stories.tsx +1 -1
- package/dist/components/form-edit/useForm.hook.d.ts +0 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/react-formio",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.13",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.modern.js",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -13,23 +13,24 @@
|
|
|
13
13
|
"prettier": "prettier '{src,test}/**/*.{ts,tsx}' --write"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@tsed/redux-utils": "1.10.
|
|
16
|
+
"@tsed/redux-utils": "1.10.13",
|
|
17
17
|
"eventemitter2": "^6.4.3",
|
|
18
18
|
"prop-types": "^15.7.2"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"choices.js": "
|
|
22
|
-
"formiojs": "
|
|
23
|
-
"lodash": "4.17.20",
|
|
24
|
-
"prop-types": "
|
|
25
|
-
"react": "
|
|
26
|
-
"react-
|
|
27
|
-
"react-table": "
|
|
28
|
-
"tooltip.js": "
|
|
21
|
+
"choices.js": ">=9.0.1",
|
|
22
|
+
"formiojs": ">=4.0.0",
|
|
23
|
+
"lodash": ">=4.17.20",
|
|
24
|
+
"prop-types": ">=15.7.2",
|
|
25
|
+
"react": ">=16.14.0",
|
|
26
|
+
"react-dom": ">=16.14.0",
|
|
27
|
+
"react-table": ">=7.6.3",
|
|
28
|
+
"tooltip.js": ">=1.3.3"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@tsed/tailwind": "1.10.
|
|
32
|
-
"@tsed/tailwind-formio": "1.10.
|
|
31
|
+
"@tsed/tailwind": "1.10.13",
|
|
32
|
+
"@tsed/tailwind-formio": "1.10.13",
|
|
33
|
+
"eslint-plugin-jsx-a11y": "^6.5.1"
|
|
33
34
|
},
|
|
34
35
|
"repository": "https://github.com/TypedProject/tsed-formio",
|
|
35
36
|
"bugs": {
|
package/readme.md
CHANGED
|
@@ -64,7 +64,7 @@ npm install formiojs choices.js --save // Install formiojs since it is a peerDep
|
|
|
64
64
|
|
|
65
65
|
## Usage
|
|
66
66
|
|
|
67
|
-
```
|
|
67
|
+
```tsx
|
|
68
68
|
import React from "react";
|
|
69
69
|
import {FormBuilder} from "@tsed/react-formio";
|
|
70
70
|
|
|
@@ -88,47 +88,78 @@ The form component is the primary component of the system. It is what takes the
|
|
|
88
88
|
|
|
89
89
|
#### Props
|
|
90
90
|
|
|
91
|
-
| Name
|
|
92
|
-
|
|
93
|
-
| `src`
|
|
94
|
-
| `url`
|
|
95
|
-
| `form`
|
|
96
|
-
| `submission` | object |
|
|
97
|
-
| `options`
|
|
91
|
+
| Name | Type | Default | Description |
|
|
92
|
+
|--------------|--------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
93
|
+
| `src` | url | | The url of the form definition. This is commonly from a form.io server. When using src, the form will automatically submit the data to that url as well. |
|
|
94
|
+
| `url` | url | | The url of the form definition. The form will not be loaded from this url and the submission will not be saved here either. This is used for file upload, oauth and other components or actions that need to know where the server is. Use this in connection with `form` |
|
|
95
|
+
| `form` | object | | Instead of loading a form from the `src` url, you can preload the form definition and pass it in with the `form` prop. You should also set `url` if you are using any advanced components like file upload or oauth. |
|
|
96
|
+
| `submission` | object | | Submission data to fill the form. You can either load a previous submission or create a submission with some pre-filled data. If you do not provide a submissions the form will initialize an empty submission using default values from the form. |
|
|
97
|
+
| `options` | object | | an options object that can pass options to the formio.js Form that is rendered. You can set options such as `readOnly`, `noAlerts` or `hide`. There are [many options to be found in the formio.js library](https://github.com/formio/formio.js/wiki/Form-Renderer#options). |
|
|
98
98
|
|
|
99
99
|
#### Event Props
|
|
100
100
|
|
|
101
101
|
You can respond to various events in the form. Simply pass in a prop with a function for one of these events.
|
|
102
102
|
|
|
103
|
-
| Name
|
|
104
|
-
|
|
105
|
-
| `onSubmit`
|
|
106
|
-
| `onSubmitDone`
|
|
107
|
-
| `onChange`
|
|
108
|
-
| `onError`
|
|
109
|
-
| `onRender`
|
|
110
|
-
| `onCustomEvent` | { `type`: string - event type, `component`: object - triggering component, `data`: object - data for component, `event`: string - raw event } | Event that is triggered from a button configured with "Event" type.
|
|
111
|
-
| `onPrevPage`
|
|
112
|
-
| `onNextPage`
|
|
113
|
-
| `onFormReady`
|
|
103
|
+
| Name | Parameters | Description |
|
|
104
|
+
|-----------------|-----------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|
|
|
105
|
+
| `onSubmit` | `submission`: object | When the submit button is pressed and the submission has started. If `src` is not provided, this will be the final submit event. |
|
|
106
|
+
| `onSubmitDone` | `submission`: object | When the submission has successfully been made to the server. This will only fire if `src` is set. |
|
|
107
|
+
| `onChange` | `submission`: object, `submission.changed`: object of what changed, `submission.isValid`: boolean - if the submission passes validations. | A value in the submission has changed. |
|
|
108
|
+
| `onError` | `errors`: array or string or boolean | Called when an error occurs during submission such as a validation issue. |
|
|
109
|
+
| `onRender` | | Triggers when the form is finished rendering. |
|
|
110
|
+
| `onCustomEvent` | { `type`: string - event type, `component`: object - triggering component, `data`: object - data for component, `event`: string - raw event } | Event that is triggered from a button configured with "Event" type. |
|
|
111
|
+
| `onPrevPage` | { `page`: integer - new page number, `submission`: object - submission data } | Triggered for wizards when "Previous" button is pressed |
|
|
112
|
+
| `onNextPage` | { `page`: integer - new page number, `submission`: object - submission data } | Triggered for wizards when "Next" button is pressed |
|
|
113
|
+
| `onFormReady` | `formInstance`: Webform/Wizard - form class instance | Called when the form gets ready state |
|
|
114
114
|
|
|
115
115
|
#### Example
|
|
116
116
|
|
|
117
|
+
##### With src/url
|
|
118
|
+
|
|
117
119
|
Give `Form` a `src` property and render:
|
|
118
120
|
|
|
119
|
-
```
|
|
121
|
+
```tsx
|
|
120
122
|
import React from 'react';
|
|
121
123
|
import ReactDOM from 'react-dom';
|
|
122
124
|
import {Form} from '@tsed/react-formio';
|
|
123
|
-
```
|
|
124
125
|
|
|
125
|
-
```javascript
|
|
126
126
|
ReactDOM.render(
|
|
127
127
|
<Form src="https://example.form.io/example" onSubmit={console.log} />
|
|
128
128
|
, document.getElementById('example')
|
|
129
129
|
);
|
|
130
130
|
```
|
|
131
131
|
|
|
132
|
+
##### With form
|
|
133
|
+
|
|
134
|
+
Give `Form` a `src` property and render:
|
|
135
|
+
|
|
136
|
+
```tsx
|
|
137
|
+
import React from 'react';
|
|
138
|
+
import ReactDOM from 'react-dom';
|
|
139
|
+
import {Form} from '@tsed/react-formio';
|
|
140
|
+
|
|
141
|
+
interface MyFormData {
|
|
142
|
+
title: string;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const form = {
|
|
146
|
+
display: 'form',
|
|
147
|
+
components: [
|
|
148
|
+
{
|
|
149
|
+
key: 'title',
|
|
150
|
+
type: 'textfield'
|
|
151
|
+
}
|
|
152
|
+
]
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
ReactDOM.render(
|
|
156
|
+
<Form<MyFormData> form={form} onSubmit={(submission) => {
|
|
157
|
+
console.log(submission)
|
|
158
|
+
}} />
|
|
159
|
+
, document.getElementById('example')
|
|
160
|
+
);
|
|
161
|
+
```
|
|
162
|
+
|
|
132
163
|
### FormBuilder
|
|
133
164
|
|
|
134
165
|
The [FormBuilder]([FormsTable](https://formio.tsed.io/?path=/story/reactformio-formbuilder--sandbox)) class can be used
|
|
@@ -141,31 +172,29 @@ the [FormEdit](https://formio.tsed.io/?path=/story/reactformio-formedit--sandbox
|
|
|
141
172
|
|
|
142
173
|
#### Props
|
|
143
174
|
|
|
144
|
-
| Name
|
|
145
|
-
|
|
146
|
-
| `form`
|
|
147
|
-
| `options` | object |
|
|
175
|
+
| Name | Type | Default | Description |
|
|
176
|
+
|-----------|--------|---------|----------------------------------------------------------------------------------------------------------------------------------------------|
|
|
177
|
+
| `form` | object | | This is the form definition object. It should at least have a `display` property set to form, wizard or pdf. |
|
|
178
|
+
| `options` | object | | an options object that can pass options to the formio.js Form that is rendered. There are many options to be found in the formio.js library. |
|
|
148
179
|
|
|
149
180
|
#### Event Props
|
|
150
181
|
|
|
151
|
-
| Name
|
|
152
|
-
|
|
153
|
-
| `onChange`
|
|
154
|
-
| `onEditComponent`
|
|
155
|
-
| `onSaveComponent`
|
|
156
|
-
| `onCancelComponent` | `component`: object | Triggered when the component settings dialog is cancelled
|
|
157
|
-
| `onDeleteComponent` | `component`: object | Triggered when a component is removed from the form
|
|
158
|
-
| `onUpdateComponent` | `component`: object | Triggered when a component is added or moved in the form
|
|
182
|
+
| Name | Parameters | Description |
|
|
183
|
+
|---------------------|---------------------|------------------------------------------------------------------|
|
|
184
|
+
| `onChange` | `schema`: object | Triggered any time the form definition changes |
|
|
185
|
+
| `onEditComponent` | `component`: object | Triggered when the component settings dialog is opened |
|
|
186
|
+
| `onSaveComponent` | `component`: object | Triggered when the component settings dialog is saved and closed |
|
|
187
|
+
| `onCancelComponent` | `component`: object | Triggered when the component settings dialog is cancelled |
|
|
188
|
+
| `onDeleteComponent` | `component`: object | Triggered when a component is removed from the form |
|
|
189
|
+
| `onUpdateComponent` | `component`: object | Triggered when a component is added or moved in the form |
|
|
159
190
|
|
|
160
191
|
#### Example
|
|
161
192
|
|
|
162
|
-
```
|
|
193
|
+
```tsx
|
|
163
194
|
import React from 'react';
|
|
164
195
|
import ReactDOM from 'react-dom';
|
|
165
196
|
import {FormBuilder} from '@tsed/react-formio';
|
|
166
|
-
```
|
|
167
197
|
|
|
168
|
-
```javascript
|
|
169
198
|
ReactDOM.render(
|
|
170
199
|
<FormBuilder form={{display: 'form'}} onChange={(schema) => console.log(schema)} />
|
|
171
200
|
, document.getElementById('builder')
|
|
@@ -179,17 +208,17 @@ the [FormBuilder]([FormsTable](https://formio.tsed.io/?path=/story/reactformio-f
|
|
|
179
208
|
|
|
180
209
|
#### Props
|
|
181
210
|
|
|
182
|
-
| Name
|
|
183
|
-
|
|
184
|
-
| `form`
|
|
185
|
-
| `options`
|
|
186
|
-
| `saveText` | string | ''
|
|
211
|
+
| Name | Type | Default | Description |
|
|
212
|
+
|------------|--------|--------------------|------------------------------------------------------|
|
|
213
|
+
| `form` | object | {display: 'form' \ | 'wizard'} | The form definition of the exiting form that is to be modified. |
|
|
214
|
+
| `options` | object | {} | The options to be passed to FormBuilder |
|
|
215
|
+
| `saveText` | string | '' | The string that will be displayed in the save-button |
|
|
187
216
|
|
|
188
217
|
#### Event Props
|
|
189
218
|
|
|
190
|
-
| Name
|
|
191
|
-
|
|
192
|
-
| `onSubmit` | form
|
|
219
|
+
| Name | Parameters | Description |
|
|
220
|
+
|------------|------------|----------------------------------------------------------------------------------------|
|
|
221
|
+
| `onSubmit` | form | Called when the save button is pressed. Will pass the form definition to the callback. |
|
|
193
222
|
|
|
194
223
|
### FormsTable
|
|
195
224
|
|
|
@@ -197,9 +226,9 @@ The [FormsTable](https://formio.tsed.io/?path=/story/reactformio-formstable--san
|
|
|
197
226
|
|
|
198
227
|
#### Props
|
|
199
228
|
|
|
200
|
-
| Name
|
|
201
|
-
|
|
202
|
-
| `data` | array of forms | []
|
|
229
|
+
| Name | Type | Default | Description |
|
|
230
|
+
|--------|----------------|---------|---------------------------------------------|
|
|
231
|
+
| `data` | array of forms | [] | A list of forms to be rendered in the grid. |
|
|
203
232
|
|
|
204
233
|
### SubmissionsTable
|
|
205
234
|
|
|
@@ -207,10 +236,10 @@ The submisison grid will render a list of submissions and allow clicking on one
|
|
|
207
236
|
|
|
208
237
|
#### Props
|
|
209
238
|
|
|
210
|
-
| Name
|
|
211
|
-
|
|
212
|
-
| `data` | array of submissions | []
|
|
213
|
-
| `form` | object
|
|
239
|
+
| Name | Type | Default | Description |
|
|
240
|
+
|--------|----------------------|---------|----------------------------------------------------------------------------------|
|
|
241
|
+
| `data` | array of submissions | [] | A list of submissions to be rendered in the grid. |
|
|
242
|
+
| `form` | object | {} | The form definition for the submissions. This is used to render the submissions. |
|
|
214
243
|
|
|
215
244
|
## Redux
|
|
216
245
|
|
|
@@ -297,6 +326,3 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
297
326
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
298
327
|
|
|
299
328
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
300
|
-
|
|
301
|
-
[travis]: https://travis-ci.org/
|
|
302
|
-
|
|
@@ -8,32 +8,30 @@ describe("ActionsTable", () => {
|
|
|
8
8
|
it("should render the table actions", async () => {
|
|
9
9
|
const onAddAction = jest.fn();
|
|
10
10
|
|
|
11
|
-
const {
|
|
11
|
+
const { getByRole, getAllByRole } = render(
|
|
12
12
|
<Sandbox {...Sandbox.args} onAddAction={onAddAction} />
|
|
13
13
|
);
|
|
14
14
|
|
|
15
|
-
const btn =
|
|
15
|
+
const btn = getByRole("button", { name: /add action/i });
|
|
16
16
|
const cells = getAllByRole("cell");
|
|
17
|
-
const
|
|
17
|
+
const options = getAllByRole("option");
|
|
18
18
|
|
|
19
|
-
expect(btn).
|
|
20
|
-
expect(btn).
|
|
21
|
-
expect(cells[0]).
|
|
22
|
-
expect(
|
|
23
|
-
Sandbox.args.availableActions.length + 1
|
|
24
|
-
);
|
|
19
|
+
expect(btn).toHaveProperty("disabled");
|
|
20
|
+
expect(btn.innerHTML).toMatch("Add action");
|
|
21
|
+
expect(cells[0].innerHTML).toMatch("Save Submission");
|
|
22
|
+
expect(options.length).toEqual(Sandbox.args.availableActions.length + 1);
|
|
25
23
|
|
|
26
|
-
expect(
|
|
27
|
-
expect(
|
|
24
|
+
expect(options[0].innerHTML).toMatch("Select an action");
|
|
25
|
+
expect(options[1].innerHTML).toMatch("Email");
|
|
28
26
|
});
|
|
29
27
|
it("should not call addAction when the default item is selected", async () => {
|
|
30
28
|
const onAddAction = jest.fn();
|
|
31
29
|
|
|
32
|
-
const {
|
|
30
|
+
const { getByRole } = render(
|
|
33
31
|
<Sandbox {...Sandbox.args} onAddAction={onAddAction} />
|
|
34
32
|
);
|
|
35
33
|
|
|
36
|
-
const btn =
|
|
34
|
+
const btn = getByRole("button", { name: /add action/i });
|
|
37
35
|
|
|
38
36
|
await fireEvent.click(btn);
|
|
39
37
|
expect(onAddAction).not.toHaveBeenCalled();
|
|
@@ -41,12 +39,12 @@ describe("ActionsTable", () => {
|
|
|
41
39
|
it("should call addAction with the selected action", async () => {
|
|
42
40
|
const onAddAction = jest.fn();
|
|
43
41
|
|
|
44
|
-
const {
|
|
42
|
+
const { getByRole } = render(
|
|
45
43
|
<Sandbox {...Sandbox.args} onAddAction={onAddAction} />
|
|
46
44
|
);
|
|
47
45
|
|
|
48
|
-
const btn =
|
|
49
|
-
const select =
|
|
46
|
+
const btn = getByRole("button", { name: /add action/i });
|
|
47
|
+
const select = getByRole("combobox");
|
|
50
48
|
|
|
51
49
|
await userEvent.selectOptions(
|
|
52
50
|
select,
|
|
@@ -55,7 +53,7 @@ describe("ActionsTable", () => {
|
|
|
55
53
|
|
|
56
54
|
await fireEvent.click(btn);
|
|
57
55
|
|
|
58
|
-
expect(btn).not.
|
|
56
|
+
expect(btn).not.toHaveProperty("disabled", true);
|
|
59
57
|
expect(onAddAction).toHaveBeenCalledWith("webhook");
|
|
60
58
|
});
|
|
61
59
|
});
|
|
@@ -53,6 +53,7 @@ export function ActionsTable({
|
|
|
53
53
|
disabled={currentAction === ""}
|
|
54
54
|
className={"btn btn-success"}
|
|
55
55
|
onClick={() => currentAction && onAddAction(currentAction)}
|
|
56
|
+
type={"submit"}
|
|
56
57
|
>
|
|
57
58
|
<i className={classnames(iconClass(undefined, "plus"), "mr-1")} />{" "}
|
|
58
59
|
{i18n("Add action")}
|
|
@@ -6,8 +6,8 @@ describe("Card", () => {
|
|
|
6
6
|
it("should render the card component", () => {
|
|
7
7
|
const { getByRole } = render(<Sandbox {...Sandbox.args} />);
|
|
8
8
|
|
|
9
|
-
const title = getByRole("
|
|
10
|
-
const body = getByRole("
|
|
9
|
+
const title = getByRole("heading");
|
|
10
|
+
const body = getByRole("article");
|
|
11
11
|
|
|
12
12
|
expect(title).toHaveTextContent("label");
|
|
13
13
|
expect(body).toHaveTextContent("test");
|
|
@@ -14,11 +14,9 @@ export function Card({
|
|
|
14
14
|
return (
|
|
15
15
|
<div className={classnames("card", className)}>
|
|
16
16
|
<div className={"card-header "}>
|
|
17
|
-
<h4 className={"card-title"}
|
|
18
|
-
{label}
|
|
19
|
-
</h4>
|
|
17
|
+
<h4 className={"card-title"}>{label}</h4>
|
|
20
18
|
</div>
|
|
21
|
-
<div className={"card-body"} role={"
|
|
19
|
+
<div className={"card-body"} role={"article"}>
|
|
22
20
|
{children}
|
|
23
21
|
</div>
|
|
24
22
|
</div>
|
|
@@ -1,61 +1,17 @@
|
|
|
1
1
|
import AllComponents from "formiojs/components";
|
|
2
|
-
import Components from "formiojs
|
|
2
|
+
import { Components } from "formiojs";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import React from "react";
|
|
5
|
-
import {
|
|
6
|
-
import { useForm } from "./useForm.hook";
|
|
5
|
+
import { useForm, UseFormHookProps } from "./useForm.hook";
|
|
7
6
|
|
|
8
7
|
Components.setComponents(AllComponents);
|
|
9
8
|
|
|
10
|
-
export interface
|
|
11
|
-
changed: any;
|
|
12
|
-
isValid: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface FormProps {
|
|
9
|
+
export interface FormProps<Data = any> extends UseFormHookProps<Data> {
|
|
16
10
|
name?: string;
|
|
17
11
|
/**
|
|
18
12
|
*
|
|
19
13
|
*/
|
|
20
14
|
className?: string;
|
|
21
|
-
/**
|
|
22
|
-
*
|
|
23
|
-
*/
|
|
24
|
-
src?: string;
|
|
25
|
-
/**
|
|
26
|
-
* url to fetch form
|
|
27
|
-
*/
|
|
28
|
-
url?: string;
|
|
29
|
-
/**
|
|
30
|
-
* Raw form object
|
|
31
|
-
*/
|
|
32
|
-
form: Partial<FormSchema>;
|
|
33
|
-
/**
|
|
34
|
-
* Data submission
|
|
35
|
-
*/
|
|
36
|
-
submission?: Submission;
|
|
37
|
-
/**
|
|
38
|
-
* Configuration option
|
|
39
|
-
*/
|
|
40
|
-
options?: FormOptions;
|
|
41
|
-
onPrevPage?: Function;
|
|
42
|
-
onNextPage?: Function;
|
|
43
|
-
onCancel?: Function;
|
|
44
|
-
onChange?: (submission: ChangedSubmission) => void;
|
|
45
|
-
onCustomEvent?: Function;
|
|
46
|
-
onComponentChange?: Function;
|
|
47
|
-
onSubmit?: Function;
|
|
48
|
-
onSubmitDone?: Function;
|
|
49
|
-
onFormLoad?: Function;
|
|
50
|
-
onError?: Function;
|
|
51
|
-
onRender?: Function;
|
|
52
|
-
onAttach?: Function;
|
|
53
|
-
onBuild?: Function;
|
|
54
|
-
onFocus?: Function;
|
|
55
|
-
onBlur?: Function;
|
|
56
|
-
onInitialized?: Function;
|
|
57
|
-
onFormReady?: (formio: any) => void;
|
|
58
|
-
formioform?: any;
|
|
59
15
|
}
|
|
60
16
|
|
|
61
17
|
export function Form(props: Partial<FormProps>) {
|
|
@@ -1,15 +1,69 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ExtendedComponentSchema, Form } from "formiojs";
|
|
2
2
|
import { get } from "lodash";
|
|
3
3
|
import cloneDeep from "lodash/cloneDeep";
|
|
4
4
|
import isEqual from "lodash/isEqual";
|
|
5
5
|
import { useEffect, useRef } from "react";
|
|
6
6
|
import { callLast } from "../../utils/callLast";
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
import { FormOptions, FormSchema, Submission } from "../../interfaces";
|
|
8
|
+
|
|
9
|
+
export interface ChangedSubmission<T = any> extends Submission<T> {
|
|
10
|
+
changed: any;
|
|
11
|
+
isValid: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface FormPageChangeProps<Data = any> {
|
|
15
|
+
page: number;
|
|
16
|
+
submission: Submission<Data>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface UseFormHookProps<Data = any> extends Record<string, any> {
|
|
20
|
+
src?: string;
|
|
21
|
+
/**
|
|
22
|
+
* url to fetch form
|
|
23
|
+
*/
|
|
24
|
+
url?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Raw form object
|
|
27
|
+
*/
|
|
28
|
+
form?: Partial<FormSchema>;
|
|
29
|
+
/**
|
|
30
|
+
* Configuration option
|
|
31
|
+
*/
|
|
32
|
+
options?: FormOptions;
|
|
33
|
+
/**
|
|
34
|
+
* Data submission
|
|
35
|
+
*/
|
|
36
|
+
submission?: Submission<Data>;
|
|
37
|
+
onPrevPage?: (obj: FormPageChangeProps<Data>) => void;
|
|
38
|
+
onNextPage?: (obj: FormPageChangeProps<Data>) => void;
|
|
39
|
+
onCancel?: Function;
|
|
40
|
+
onChange?: (submission: ChangedSubmission) => void;
|
|
41
|
+
onCustomEvent?: (obj: {
|
|
42
|
+
type: string;
|
|
43
|
+
event: string;
|
|
44
|
+
component: ExtendedComponentSchema;
|
|
45
|
+
data: any;
|
|
46
|
+
}) => void;
|
|
47
|
+
onComponentChange?: (component: ExtendedComponentSchema) => void;
|
|
48
|
+
onSubmit?: (submission: Submission<Data>) => void;
|
|
49
|
+
onSubmitDone?: (submission: Submission<Data>) => void;
|
|
50
|
+
onFormLoad?: Function;
|
|
51
|
+
onError?: (errors: any) => void;
|
|
52
|
+
onRender?: () => void;
|
|
53
|
+
onAttach?: Function;
|
|
54
|
+
onBuild?: Function;
|
|
55
|
+
onFocus?: Function;
|
|
56
|
+
onBlur?: Function;
|
|
57
|
+
onInitialized?: Function;
|
|
58
|
+
onFormReady?: (formio: Form) => void;
|
|
59
|
+
formioform?: any;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function useForm<Data = any>(props: UseFormHookProps<Data>) {
|
|
9
63
|
const { src, form, options = {}, submission, url, ...funcs } = props;
|
|
10
64
|
const element = useRef<any>();
|
|
11
65
|
const isLoaded = useRef<boolean>();
|
|
12
|
-
const instance = useRef<
|
|
66
|
+
const instance = useRef<Form>();
|
|
13
67
|
const events = useRef<Map<string, any>>(new Map());
|
|
14
68
|
|
|
15
69
|
const createWebForm = (srcOrForm: any, options: any) => {
|
|
@@ -19,7 +73,7 @@ export const useForm = (props: any): any => {
|
|
|
19
73
|
|
|
20
74
|
if (!instance.current) {
|
|
21
75
|
isLoaded.current = false;
|
|
22
|
-
instance.current = new
|
|
76
|
+
instance.current = new Form(element.current, srcOrForm, options);
|
|
23
77
|
|
|
24
78
|
instance.current.onAny((event: string, ...args: any[]): void => {
|
|
25
79
|
if (!instance.current) {
|
|
@@ -88,7 +142,7 @@ export const useForm = (props: any): any => {
|
|
|
88
142
|
if (src) {
|
|
89
143
|
if (instance.current) {
|
|
90
144
|
isLoaded.current = false;
|
|
91
|
-
instance.current.destroy(true);
|
|
145
|
+
(instance.current as any).destroy(true);
|
|
92
146
|
}
|
|
93
147
|
|
|
94
148
|
createWebForm(src, options);
|
|
@@ -102,7 +156,7 @@ export const useForm = (props: any): any => {
|
|
|
102
156
|
|
|
103
157
|
return () => {
|
|
104
158
|
isLoaded.current = false;
|
|
105
|
-
instance.current && instance.current.destroy(true);
|
|
159
|
+
instance.current && (instance.current as any).destroy(true);
|
|
106
160
|
};
|
|
107
161
|
}, []);
|
|
108
162
|
|
|
@@ -118,4 +172,4 @@ export const useForm = (props: any): any => {
|
|
|
118
172
|
return {
|
|
119
173
|
element
|
|
120
174
|
};
|
|
121
|
-
}
|
|
175
|
+
}
|
|
@@ -9,7 +9,7 @@ import React, {
|
|
|
9
9
|
} from "react";
|
|
10
10
|
import { FormOptions, FormSchema, Submission } from "../../interfaces";
|
|
11
11
|
import { Card } from "../card/card.component";
|
|
12
|
-
import {
|
|
12
|
+
import { Form } from "../form/form.component";
|
|
13
13
|
import {
|
|
14
14
|
AccessRoles,
|
|
15
15
|
dataAccessToSubmissions,
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
submissionsToDataAccess,
|
|
21
21
|
updateSubmissions
|
|
22
22
|
} from "./formAccess.utils";
|
|
23
|
+
import { ChangedSubmission } from "../form/useForm.hook";
|
|
23
24
|
|
|
24
25
|
export interface FormAccessProps {
|
|
25
26
|
form: Partial<FormSchema>;
|
|
@@ -38,7 +38,7 @@ function mapSettingsForm({ action, ...settingsForm }: any): any {
|
|
|
38
38
|
export interface FormActionProps {
|
|
39
39
|
actionInfo: Partial<ActionSchema>;
|
|
40
40
|
submission?: Partial<Submission>;
|
|
41
|
-
onSubmit?:
|
|
41
|
+
onSubmit?: (submission: Submission<ActionSchema>) => void;
|
|
42
42
|
options: FormOptions;
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
2
|
+
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
1
3
|
import { ComponentSchema } from "formiojs";
|
|
2
4
|
import AllComponents from "formiojs/components";
|
|
3
5
|
import Components from "formiojs/components/Components";
|
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
import PropTypes from "prop-types";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import { FormOptions
|
|
3
|
+
import { FormOptions } from "../../interfaces/FormOptions";
|
|
4
4
|
import { FormBuilder } from "../form-builder/formBuilder.component";
|
|
5
5
|
import { FormEditCTAs } from "./formCtas.component";
|
|
6
6
|
import { FormParameters } from "./formParameters.component";
|
|
7
|
-
import {
|
|
7
|
+
import { useFormEdit, UseFormEditHookProps } from "./useFormEdit.hook";
|
|
8
8
|
|
|
9
|
-
export interface FormEditProps extends
|
|
10
|
-
form?: Partial<FormSchema>;
|
|
11
|
-
options?: FormOptions;
|
|
12
|
-
typeChoices?: { label: string; value: any }[];
|
|
13
|
-
displayChoices?: { label: string; value: any }[];
|
|
14
|
-
enableTags?: boolean;
|
|
15
|
-
onSubmit?: (form: FormSchema) => void;
|
|
16
|
-
onCopy?: (form: FormSchema) => void;
|
|
9
|
+
export interface FormEditProps extends UseFormEditHookProps {
|
|
17
10
|
builder?: any;
|
|
11
|
+
options?: FormOptions;
|
|
18
12
|
}
|
|
19
13
|
|
|
20
14
|
export function FormEdit(props: FormEditProps) {
|
|
@@ -30,7 +24,7 @@ export function FormEdit(props: FormEditProps) {
|
|
|
30
24
|
reset,
|
|
31
25
|
onSubmit,
|
|
32
26
|
onCopy
|
|
33
|
-
} =
|
|
27
|
+
} = useFormEdit(props);
|
|
34
28
|
const { options = {}, builder } = props;
|
|
35
29
|
|
|
36
30
|
return (
|
|
@@ -2,22 +2,16 @@ import { useEffect, useReducer } from "react";
|
|
|
2
2
|
import { FormSchema } from "../../interfaces/FormSchema";
|
|
3
3
|
import { createInitialState, hasChanged, reducer } from "./formEdit.reducer";
|
|
4
4
|
|
|
5
|
-
export interface
|
|
6
|
-
form
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
hasUndo: boolean;
|
|
13
|
-
hasRedo: boolean;
|
|
14
|
-
onSubmit: () => void;
|
|
15
|
-
onCopy: () => void;
|
|
16
|
-
formChange: (newForm: Partial<FormSchema>) => void;
|
|
17
|
-
setChange: (path: string, value: any) => void;
|
|
5
|
+
export interface UseFormEditHookProps extends Record<string, unknown> {
|
|
6
|
+
form?: Partial<FormSchema>;
|
|
7
|
+
typeChoices?: { label: string; value: any }[];
|
|
8
|
+
displayChoices?: { label: string; value: any }[];
|
|
9
|
+
enableTags?: boolean;
|
|
10
|
+
onSubmit?: (form: Partial<FormSchema>) => void;
|
|
11
|
+
onCopy?: (form: Partial<FormSchema>) => void;
|
|
18
12
|
}
|
|
19
13
|
|
|
20
|
-
export function
|
|
14
|
+
export function useFormEdit(props: UseFormEditHookProps) {
|
|
21
15
|
const [{ current, future, past }, dispatchFormAction] = useReducer(
|
|
22
16
|
reducer,
|
|
23
17
|
createInitialState(props)
|