@tsed/tailwind-formio 3.0.0-alpha.3 → 3.0.0-alpha.4
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/package.json +1 -1
- package/src/templates/stories/__fixtures__/WrapperForm.jsx +103 -0
- package/src/templates/stories/__fixtures__/form-firstname.fixture.json +256 -0
- package/src/templates/stories/__fixtures__/form.fixtures.js +1840 -0
- package/src/templates/stories/__fixtures__/useEditForm.jsx +82 -0
- package/src/templates/stories/form-integration.stories.jsx +227 -0
- package/src/templates/stories/form.stories.jsx +466 -0
package/package.json
CHANGED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Form } from "formiojs";
|
|
2
|
+
import cloneDeep from "lodash/cloneDeep";
|
|
3
|
+
import React, { useEffect, useRef } from "react";
|
|
4
|
+
|
|
5
|
+
function createCustomValidation(customAction, ref) {
|
|
6
|
+
return async (submission, next) => {
|
|
7
|
+
try {
|
|
8
|
+
const updatedSubmission = await customAction(submission);
|
|
9
|
+
|
|
10
|
+
next(null);
|
|
11
|
+
|
|
12
|
+
ref.current.onSubmit(updatedSubmission, true);
|
|
13
|
+
} catch (er) {
|
|
14
|
+
next(er.errors || er);
|
|
15
|
+
} finally {
|
|
16
|
+
ref.current.submissionInProcess = false;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function listenEvents(props, webform) {
|
|
22
|
+
Object.keys(props).forEach((key) => {
|
|
23
|
+
if (key.startsWith("on") && key !== "onAsyncSubmit") {
|
|
24
|
+
// remove first 2 characters and lowercase the first letter
|
|
25
|
+
const eventName = key.charAt(2).toLowerCase() + key.slice(3);
|
|
26
|
+
|
|
27
|
+
webform.on(eventName, props[key]);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function useForm({ options, form, src, FormClass = Form, submission, ...props }) {
|
|
33
|
+
const renderElement = useRef();
|
|
34
|
+
const instanceRef = useRef();
|
|
35
|
+
const webFormRef = useRef();
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (renderElement.current === null) {
|
|
39
|
+
console.warn("Form element not found");
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!form && !src) {
|
|
44
|
+
console.warn("Form source not found");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let opts = options || {};
|
|
49
|
+
|
|
50
|
+
if (props.onAsyncSubmit) {
|
|
51
|
+
opts.hooks = opts.hooks || {};
|
|
52
|
+
opts.hooks.customValidation = createCustomValidation(props.onAsyncSubmit, webFormRef);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const formio = new FormClass(renderElement.current, form ? cloneDeep(form) : src, opts);
|
|
56
|
+
formio.toJSON = () => ({ __FORM__: true });
|
|
57
|
+
|
|
58
|
+
formio.ready.then((webform) => {
|
|
59
|
+
webFormRef.current = webform;
|
|
60
|
+
// FIX to avoid JSON.stringify circular reference
|
|
61
|
+
webform.toJSON = () => ({ __WEBFORM__: true });
|
|
62
|
+
|
|
63
|
+
console.log("Created form");
|
|
64
|
+
|
|
65
|
+
if (submission) {
|
|
66
|
+
webform.setSubmission(submission);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
listenEvents(props, webform);
|
|
70
|
+
|
|
71
|
+
renderElement.current.className = "formio-form-ready";
|
|
72
|
+
instanceRef.current = webform;
|
|
73
|
+
|
|
74
|
+
if (props.onFormReady) {
|
|
75
|
+
// FIX for unit test when onFormReady is a stub
|
|
76
|
+
props.onFormReady(webform);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return () => {
|
|
81
|
+
return formio.destroy(true);
|
|
82
|
+
};
|
|
83
|
+
}, [form, src]);
|
|
84
|
+
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (submission && instanceRef.current) {
|
|
87
|
+
console.log("Setting submission", submission);
|
|
88
|
+
webFormRef.current.setSubmission(submission);
|
|
89
|
+
}
|
|
90
|
+
}, [submission]);
|
|
91
|
+
|
|
92
|
+
return { element: renderElement };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function WrapperForm({ className, style, ...props }) {
|
|
96
|
+
const { element } = useForm(props);
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<div className={className} style={style}>
|
|
100
|
+
<div data-testid='formio-container' ref={element} />
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "form",
|
|
3
|
+
"display": "form",
|
|
4
|
+
"tags": [],
|
|
5
|
+
"components": [
|
|
6
|
+
{
|
|
7
|
+
"label": "First name",
|
|
8
|
+
"labelPosition": "top",
|
|
9
|
+
"placeholder": "",
|
|
10
|
+
"description": "",
|
|
11
|
+
"tooltip": "",
|
|
12
|
+
"prefix": "",
|
|
13
|
+
"suffix": "",
|
|
14
|
+
"widget": {
|
|
15
|
+
"type": "input"
|
|
16
|
+
},
|
|
17
|
+
"inputMask": "",
|
|
18
|
+
"displayMask": "",
|
|
19
|
+
"applyMaskOn": "change",
|
|
20
|
+
"allowMultipleMasks": false,
|
|
21
|
+
"customClass": "",
|
|
22
|
+
"tabindex": "",
|
|
23
|
+
"autocomplete": "",
|
|
24
|
+
"hidden": false,
|
|
25
|
+
"hideLabel": false,
|
|
26
|
+
"showWordCount": false,
|
|
27
|
+
"showCharCount": false,
|
|
28
|
+
"mask": false,
|
|
29
|
+
"autofocus": false,
|
|
30
|
+
"spellcheck": true,
|
|
31
|
+
"disabled": false,
|
|
32
|
+
"tableView": true,
|
|
33
|
+
"modalEdit": false,
|
|
34
|
+
"multiple": false,
|
|
35
|
+
"persistent": true,
|
|
36
|
+
"inputFormat": "plain",
|
|
37
|
+
"protected": false,
|
|
38
|
+
"dbIndex": false,
|
|
39
|
+
"case": "",
|
|
40
|
+
"truncateMultipleSpaces": false,
|
|
41
|
+
"encrypted": false,
|
|
42
|
+
"redrawOn": "",
|
|
43
|
+
"clearOnHide": true,
|
|
44
|
+
"customDefaultValue": "",
|
|
45
|
+
"calculateValue": "",
|
|
46
|
+
"calculateServer": false,
|
|
47
|
+
"allowCalculateOverride": false,
|
|
48
|
+
"validateOn": "change",
|
|
49
|
+
"validate": {
|
|
50
|
+
"required": false,
|
|
51
|
+
"pattern": "",
|
|
52
|
+
"customMessage": "",
|
|
53
|
+
"custom": "",
|
|
54
|
+
"customPrivate": false,
|
|
55
|
+
"json": "",
|
|
56
|
+
"minLength": "",
|
|
57
|
+
"maxLength": "",
|
|
58
|
+
"strictDateValidation": false,
|
|
59
|
+
"multiple": false,
|
|
60
|
+
"unique": false
|
|
61
|
+
},
|
|
62
|
+
"unique": false,
|
|
63
|
+
"validateWhenHidden": false,
|
|
64
|
+
"errorLabel": "",
|
|
65
|
+
"errors": "",
|
|
66
|
+
"key": "firstName",
|
|
67
|
+
"tags": [],
|
|
68
|
+
"properties": {},
|
|
69
|
+
"conditional": {
|
|
70
|
+
"show": null,
|
|
71
|
+
"when": null,
|
|
72
|
+
"eq": "",
|
|
73
|
+
"json": ""
|
|
74
|
+
},
|
|
75
|
+
"customConditional": "",
|
|
76
|
+
"logic": [],
|
|
77
|
+
"attributes": {},
|
|
78
|
+
"overlay": {
|
|
79
|
+
"style": "",
|
|
80
|
+
"page": "",
|
|
81
|
+
"left": "",
|
|
82
|
+
"top": "",
|
|
83
|
+
"width": "",
|
|
84
|
+
"height": ""
|
|
85
|
+
},
|
|
86
|
+
"type": "textfield",
|
|
87
|
+
"dataGridLabel": false,
|
|
88
|
+
"input": true,
|
|
89
|
+
"refreshOn": "",
|
|
90
|
+
"addons": [],
|
|
91
|
+
"inputType": "text",
|
|
92
|
+
"defaultValue": ""
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"label": "Last name",
|
|
96
|
+
"labelPosition": "top",
|
|
97
|
+
"placeholder": "",
|
|
98
|
+
"description": "",
|
|
99
|
+
"tooltip": "",
|
|
100
|
+
"prefix": "",
|
|
101
|
+
"suffix": "",
|
|
102
|
+
"widget": {
|
|
103
|
+
"type": "input"
|
|
104
|
+
},
|
|
105
|
+
"inputMask": "",
|
|
106
|
+
"displayMask": "",
|
|
107
|
+
"applyMaskOn": "change",
|
|
108
|
+
"allowMultipleMasks": false,
|
|
109
|
+
"customClass": "",
|
|
110
|
+
"tabindex": "",
|
|
111
|
+
"autocomplete": "",
|
|
112
|
+
"hidden": false,
|
|
113
|
+
"hideLabel": false,
|
|
114
|
+
"showWordCount": false,
|
|
115
|
+
"showCharCount": false,
|
|
116
|
+
"mask": false,
|
|
117
|
+
"autofocus": false,
|
|
118
|
+
"spellcheck": true,
|
|
119
|
+
"disabled": false,
|
|
120
|
+
"tableView": true,
|
|
121
|
+
"modalEdit": false,
|
|
122
|
+
"multiple": false,
|
|
123
|
+
"persistent": true,
|
|
124
|
+
"inputFormat": "plain",
|
|
125
|
+
"protected": false,
|
|
126
|
+
"dbIndex": false,
|
|
127
|
+
"case": "",
|
|
128
|
+
"truncateMultipleSpaces": false,
|
|
129
|
+
"encrypted": false,
|
|
130
|
+
"redrawOn": "",
|
|
131
|
+
"clearOnHide": true,
|
|
132
|
+
"customDefaultValue": "",
|
|
133
|
+
"calculateValue": "",
|
|
134
|
+
"calculateServer": false,
|
|
135
|
+
"allowCalculateOverride": false,
|
|
136
|
+
"validateOn": "change",
|
|
137
|
+
"validate": {
|
|
138
|
+
"required": false,
|
|
139
|
+
"pattern": "",
|
|
140
|
+
"customMessage": "",
|
|
141
|
+
"custom": "",
|
|
142
|
+
"customPrivate": false,
|
|
143
|
+
"json": "",
|
|
144
|
+
"minLength": "",
|
|
145
|
+
"maxLength": "",
|
|
146
|
+
"strictDateValidation": false,
|
|
147
|
+
"multiple": false,
|
|
148
|
+
"unique": false
|
|
149
|
+
},
|
|
150
|
+
"unique": false,
|
|
151
|
+
"validateWhenHidden": false,
|
|
152
|
+
"errorLabel": "",
|
|
153
|
+
"errors": "",
|
|
154
|
+
"key": "lastName",
|
|
155
|
+
"tags": [],
|
|
156
|
+
"properties": {},
|
|
157
|
+
"conditional": {
|
|
158
|
+
"show": null,
|
|
159
|
+
"when": null,
|
|
160
|
+
"eq": "",
|
|
161
|
+
"json": ""
|
|
162
|
+
},
|
|
163
|
+
"customConditional": "",
|
|
164
|
+
"logic": [],
|
|
165
|
+
"attributes": {},
|
|
166
|
+
"overlay": {
|
|
167
|
+
"style": "",
|
|
168
|
+
"page": "",
|
|
169
|
+
"left": "",
|
|
170
|
+
"top": "",
|
|
171
|
+
"width": "",
|
|
172
|
+
"height": ""
|
|
173
|
+
},
|
|
174
|
+
"type": "textfield",
|
|
175
|
+
"dataGridLabel": false,
|
|
176
|
+
"input": true,
|
|
177
|
+
"refreshOn": "",
|
|
178
|
+
"addons": [],
|
|
179
|
+
"inputType": "text",
|
|
180
|
+
"defaultValue": ""
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"type": "button",
|
|
184
|
+
"label": "Submit",
|
|
185
|
+
"key": "submit",
|
|
186
|
+
"size": "md",
|
|
187
|
+
"block": false,
|
|
188
|
+
"action": "submit",
|
|
189
|
+
"disableOnInvalid": true,
|
|
190
|
+
"theme": "primary",
|
|
191
|
+
"input": true,
|
|
192
|
+
"placeholder": "",
|
|
193
|
+
"prefix": "",
|
|
194
|
+
"customClass": "",
|
|
195
|
+
"suffix": "",
|
|
196
|
+
"multiple": false,
|
|
197
|
+
"defaultValue": null,
|
|
198
|
+
"protected": false,
|
|
199
|
+
"unique": false,
|
|
200
|
+
"persistent": false,
|
|
201
|
+
"hidden": false,
|
|
202
|
+
"clearOnHide": true,
|
|
203
|
+
"refreshOn": "",
|
|
204
|
+
"redrawOn": "",
|
|
205
|
+
"tableView": false,
|
|
206
|
+
"modalEdit": false,
|
|
207
|
+
"labelPosition": "top",
|
|
208
|
+
"description": "",
|
|
209
|
+
"errorLabel": "",
|
|
210
|
+
"tooltip": "",
|
|
211
|
+
"hideLabel": false,
|
|
212
|
+
"tabindex": "",
|
|
213
|
+
"disabled": false,
|
|
214
|
+
"autofocus": false,
|
|
215
|
+
"dbIndex": false,
|
|
216
|
+
"customDefaultValue": "",
|
|
217
|
+
"calculateValue": "",
|
|
218
|
+
"calculateServer": false,
|
|
219
|
+
"widget": {
|
|
220
|
+
"type": "input"
|
|
221
|
+
},
|
|
222
|
+
"attributes": {},
|
|
223
|
+
"validateOn": "change",
|
|
224
|
+
"validate": {
|
|
225
|
+
"required": false,
|
|
226
|
+
"custom": "",
|
|
227
|
+
"customPrivate": false,
|
|
228
|
+
"strictDateValidation": false,
|
|
229
|
+
"multiple": false,
|
|
230
|
+
"unique": false
|
|
231
|
+
},
|
|
232
|
+
"conditional": {
|
|
233
|
+
"show": null,
|
|
234
|
+
"when": null,
|
|
235
|
+
"eq": ""
|
|
236
|
+
},
|
|
237
|
+
"overlay": {
|
|
238
|
+
"style": "",
|
|
239
|
+
"left": "",
|
|
240
|
+
"top": "",
|
|
241
|
+
"width": "",
|
|
242
|
+
"height": ""
|
|
243
|
+
},
|
|
244
|
+
"allowCalculateOverride": false,
|
|
245
|
+
"encrypted": false,
|
|
246
|
+
"showCharCount": false,
|
|
247
|
+
"showWordCount": false,
|
|
248
|
+
"properties": {},
|
|
249
|
+
"allowMultipleMasks": false,
|
|
250
|
+
"leftIcon": "",
|
|
251
|
+
"rightIcon": "",
|
|
252
|
+
"dataGridLabel": true,
|
|
253
|
+
"addons": []
|
|
254
|
+
}
|
|
255
|
+
]
|
|
256
|
+
}
|