@bolttech/form-engine 3.1.2-beta.1 → 3.1.2-beta.2
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/README.md +108 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ This is an adapter to be used with the bolttech form engine. Compatible with Nex
|
|
|
17
17
|
6. [schema components](#schema-components)
|
|
18
18
|
|
|
19
19
|
- 6.1 [formatters](#formatters)
|
|
20
|
-
- 6.2 [masks]
|
|
20
|
+
- 6.2 [masks](#masks)
|
|
21
21
|
- 6.3 [nameToSubmit](#nametosubmit)
|
|
22
22
|
- 6.4 [props](#props)
|
|
23
23
|
- 6.5 [validations](#validations)
|
|
@@ -37,6 +37,7 @@ This is an adapter to be used with the bolttech form engine. Compatible with Nex
|
|
|
37
37
|
|
|
38
38
|
9. [AsFormField](#asformfield)
|
|
39
39
|
10. [AsFormFieldBuilder](#asformfieldbuilder)
|
|
40
|
+
11. [AsFormFieldRepeater](#asformfieldrepeater)
|
|
40
41
|
|
|
41
42
|
<a id="sample"></a>
|
|
42
43
|
|
|
@@ -1187,3 +1188,109 @@ Other than schema component properties like `validations`, `api`, etc.., it has
|
|
|
1187
1188
|
| name | string | field name to be identified on the form |
|
|
1188
1189
|
| formIndex | string | index of the form to be identified on the formGroup |
|
|
1189
1190
|
| component | string | if mappers is provided from the formgroup context, you can assign the mapper by it's name instead of whole mapper config |
|
|
1191
|
+
|
|
1192
|
+
<a id="asformfieldrepeater"></a>
|
|
1193
|
+
|
|
1194
|
+
## **AsFormFieldRepeater**
|
|
1195
|
+
|
|
1196
|
+
Component adapter to aid managing multiple forms that shares the same inputs
|
|
1197
|
+
|
|
1198
|
+
Props:
|
|
1199
|
+
|
|
1200
|
+
| Attr | Type |Description |
|
|
1201
|
+
| --------------------------- | --------------------------------------------------------- | -------------------------------------------------------------------------- |
|
|
1202
|
+
| RepeaterComponent | ElementType<{ formIndex: string }> | Component with form schema or AsFormFieldBuilder elements |
|
|
1203
|
+
| addFieldName | string | name of the button in the RepeaterComponent to add forms |
|
|
1204
|
+
| removeFieldName | string | name of the button in the RepeaterComponent to remove forms |
|
|
1205
|
+
| existingElements | Record<string, unknown>[] | existing values emmitted from stateUpdater to restore previous used values |
|
|
1206
|
+
| stateUpdater | (payload: TFormGroupOnDataEventPayload<unknown>) => void; | callback function that reacts to RepeaterComponet values changes |
|
|
1207
|
+
| formPrefix | string | prefix for form names ex, prefix: foo, forms: ["foo1","foo2","foo3"] |
|
|
1208
|
+
| RepeaterFooter | ElementType<{ formIndex: string }> | Component with a button to add forms on the last position |
|
|
1209
|
+
|
|
1210
|
+
Common use case for this Adapter is to manage multiple forms that collects the same data ex: multiple person personal data
|
|
1211
|
+
|
|
1212
|
+
# Example
|
|
1213
|
+
|
|
1214
|
+
## RepeaterComponent
|
|
1215
|
+
|
|
1216
|
+
```javascript
|
|
1217
|
+
const FormElement = ({ formIndex }: { formIndex: string }) => {
|
|
1218
|
+
return (
|
|
1219
|
+
<>
|
|
1220
|
+
<AsFormFieldBuilder formIndex={formIndex} name="foo" component="input" props={{ label: 'foo' }} />
|
|
1221
|
+
<AsFormFieldBuilder formIndex={formIndex} name="bar" component="input" props={{ label: 'bar' }} />
|
|
1222
|
+
<AsFormFieldBuilder
|
|
1223
|
+
formIndex={formIndex}
|
|
1224
|
+
name="addForm"
|
|
1225
|
+
component="button"
|
|
1226
|
+
props={{
|
|
1227
|
+
text: 'add element',
|
|
1228
|
+
}}
|
|
1229
|
+
/>
|
|
1230
|
+
<AsFormFieldBuilder
|
|
1231
|
+
formIndex={formIndex}
|
|
1232
|
+
name="removeForm"
|
|
1233
|
+
component="button"
|
|
1234
|
+
props={{
|
|
1235
|
+
text: 'remove element',
|
|
1236
|
+
}}
|
|
1237
|
+
/>
|
|
1238
|
+
</>
|
|
1239
|
+
);
|
|
1240
|
+
};
|
|
1241
|
+
```
|
|
1242
|
+
|
|
1243
|
+
Important notes when developing this component is that it needs to receive an object with a key **formIndex**
|
|
1244
|
+
|
|
1245
|
+
Optionally, but to add form management functionality, add two buttons with **ON_FIELD_CLICK** event capture (can't be of type submit)
|
|
1246
|
+
both that Field button names will be needed on the next step
|
|
1247
|
+
|
|
1248
|
+
## RepeaterFooter
|
|
1249
|
+
|
|
1250
|
+
Optionally, you can develop a footer component with a button that will be added the bottom of the repeated forms
|
|
1251
|
+
and when you press that button will add a form at the bottom of the list
|
|
1252
|
+
|
|
1253
|
+
It's props needs to be an objet with a **formIndex** key, the button needs to have **ON_FIELD_CLICK** event capture (can't be of type submit)
|
|
1254
|
+
Note: the button name needs to be different from the names you gave to the buttons you are passing on the RepeaterComponent
|
|
1255
|
+
|
|
1256
|
+
```javascript
|
|
1257
|
+
const FormElementFooter = ({ formIndex }: { formIndex: string }) => {
|
|
1258
|
+
return (
|
|
1259
|
+
<AsFormFieldBuilder
|
|
1260
|
+
formIndex={formIndex}
|
|
1261
|
+
name="addFormBelow"
|
|
1262
|
+
component="button"
|
|
1263
|
+
props={{
|
|
1264
|
+
text: 'add element below',
|
|
1265
|
+
}}
|
|
1266
|
+
/>
|
|
1267
|
+
);
|
|
1268
|
+
};
|
|
1269
|
+
```
|
|
1270
|
+
|
|
1271
|
+
## AsFormFieldRepeater
|
|
1272
|
+
|
|
1273
|
+
Set the AsFormFieldRepeater adapter with the element you created above and the names that you gave to the button fields
|
|
1274
|
+
|
|
1275
|
+
```javascript
|
|
1276
|
+
<AsFormFieldRepeater
|
|
1277
|
+
RepeaterComponent={FormElement}
|
|
1278
|
+
RepeaterFooter={FormElementFooter}
|
|
1279
|
+
addFieldName="addForm"
|
|
1280
|
+
removeFieldName="removeForm"
|
|
1281
|
+
formPrefix="insured"
|
|
1282
|
+
stateUpdater={(payload) => {
|
|
1283
|
+
console.log(payload);
|
|
1284
|
+
}}
|
|
1285
|
+
/>
|
|
1286
|
+
```
|
|
1287
|
+
|
|
1288
|
+
**RepeaterComponent** and **RepeaterFooter** you set the elements created above
|
|
1289
|
+
|
|
1290
|
+
**addFieldName** you set the name to the button that will add a form on the position it's being clicked
|
|
1291
|
+
|
|
1292
|
+
**removeFieldName** you set the name to the button that will remove a form on the position it's being clicked
|
|
1293
|
+
|
|
1294
|
+
**formPrefix** the prefix for the forms emmited on **stateUpdater** enumerated
|
|
1295
|
+
|
|
1296
|
+
**stateUpdater** callback function that will receive the form values (similar to onData)
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bolttech/form-engine",
|
|
3
|
-
"version": "3.1.2-beta.
|
|
3
|
+
"version": "3.1.2-beta.2",
|
|
4
4
|
"description": "A react adapter for bolttech form engine",
|
|
5
5
|
"module": "./index.esm.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./index.esm.js",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@bolttech/form-engine-core": "1.0.2-beta.
|
|
9
|
+
"@bolttech/form-engine-core": "1.0.2-beta.2",
|
|
10
10
|
"react": "18.2.0"
|
|
11
11
|
},
|
|
12
12
|
"peerDependencies": {}
|