@bolttech/form-engine 3.1.2-beta.0 → 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/index.esm.js +8 -7
- 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/index.esm.js
CHANGED
|
@@ -2357,14 +2357,14 @@ function Form({
|
|
|
2357
2357
|
},
|
|
2358
2358
|
children: "try submit"
|
|
2359
2359
|
}), jsx("br", {}), jsx("hr", {})]
|
|
2360
|
-
}),
|
|
2360
|
+
}), jsxs("form", {
|
|
2361
2361
|
onSubmit: handleSubmit,
|
|
2362
|
-
children: jsx(BuildSchemaAsFields, {
|
|
2362
|
+
children: [jsx(BuildSchemaAsFields, {
|
|
2363
2363
|
formIndex: schemaIndex,
|
|
2364
2364
|
mappers: mappers,
|
|
2365
2365
|
components: schema === null || schema === void 0 ? void 0 : schema.components,
|
|
2366
2366
|
mountedForm: mounted
|
|
2367
|
-
})
|
|
2367
|
+
}), children]
|
|
2368
2368
|
})]
|
|
2369
2369
|
});
|
|
2370
2370
|
}
|
|
@@ -2429,6 +2429,7 @@ const FieldWrapper = ({
|
|
|
2429
2429
|
}) => {
|
|
2430
2430
|
var _a, _b, _c, _d;
|
|
2431
2431
|
const localContext = useFormGroupContext({});
|
|
2432
|
+
const fieldMapper = mapper || ((_a = localContext.mappers) === null || _a === void 0 ? void 0 : _a.find(mapper => mapper.componentName === component));
|
|
2432
2433
|
/**
|
|
2433
2434
|
* picks the right context prioritizing the context passed as prop
|
|
2434
2435
|
*/
|
|
@@ -2456,7 +2457,7 @@ const FieldWrapper = ({
|
|
|
2456
2457
|
return returnProps;
|
|
2457
2458
|
}, [props]);
|
|
2458
2459
|
const [valueState, setValueState] = useState((fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.stateValue) || {
|
|
2459
|
-
[((
|
|
2460
|
+
[((_b = fieldMapper === null || fieldMapper === void 0 ? void 0 : fieldMapper.events) === null || _b === void 0 ? void 0 : _b.setValue) || 'value']: ''
|
|
2460
2461
|
});
|
|
2461
2462
|
const [state, setState] = useState({
|
|
2462
2463
|
visibility: typeof visibility === 'boolean' ? visibility : true,
|
|
@@ -2516,7 +2517,7 @@ const FieldWrapper = ({
|
|
|
2516
2517
|
* to the corresponding prop defined on the mappers
|
|
2517
2518
|
*/
|
|
2518
2519
|
const mapProps = useMemo(() => {
|
|
2519
|
-
const events =
|
|
2520
|
+
const events = fieldMapper === null || fieldMapper === void 0 ? void 0 : fieldMapper.events;
|
|
2520
2521
|
const props = {};
|
|
2521
2522
|
if (events === null || events === void 0 ? void 0 : events.onBlur) props[events.onBlur] = () => handleEvent('ON_FIELD_BLUR');
|
|
2522
2523
|
if (events === null || events === void 0 ? void 0 : events.getValue) props[events.getValue] = handleChange;
|
|
@@ -2545,7 +2546,7 @@ const FieldWrapper = ({
|
|
|
2545
2546
|
padding: '0px',
|
|
2546
2547
|
margin: '0px'
|
|
2547
2548
|
},
|
|
2548
|
-
children: ["order:", (
|
|
2549
|
+
children: ["order:", (_c = fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.originalSchema) === null || _c === void 0 ? void 0 : _c.order]
|
|
2549
2550
|
}), jsxs("b", {
|
|
2550
2551
|
style: {
|
|
2551
2552
|
padding: '0px',
|
|
@@ -2556,7 +2557,7 @@ const FieldWrapper = ({
|
|
|
2556
2557
|
}), jsx(FieldWrapperComponentRender, {
|
|
2557
2558
|
props: Object.assign(Object.assign(Object.assign(Object.assign({}, mapProps), state.props), state.errors), valueState),
|
|
2558
2559
|
fieldInstance: fieldInstance,
|
|
2559
|
-
mapper:
|
|
2560
|
+
mapper: fieldMapper,
|
|
2560
2561
|
children: children ? children : ((_d = state === null || state === void 0 ? void 0 : state.props) === null || _d === void 0 ? void 0 : _d.children) ? state === null || state === void 0 ? void 0 : state.props.children : null
|
|
2561
2562
|
})]
|
|
2562
2563
|
}) : jsx(Fragment, {});
|
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": {}
|