@bolttech/form-engine 3.0.1-beta.7 → 3.0.2-beta.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/README.md CHANGED
@@ -24,6 +24,7 @@ This is an adapter to be used with the bolttech form engine. Compatible with Nex
24
24
  - 6.6 [api](#api)
25
25
  - 6.7 [resetValues](#resetvalues)
26
26
  - 6.8 [visibilityConditions](#visibilityconditions)
27
+ - 6.9 [resetPropertyValues](#resetpropertyvalues)
27
28
 
28
29
  7. [templating](#templating)
29
30
 
@@ -36,6 +37,7 @@ This is an adapter to be used with the bolttech form engine. Compatible with Nex
36
37
  10. [AsFormFieldBuilder](#asformfieldbuilder)
37
38
 
38
39
  <a id="sample"></a>
40
+
39
41
  ## **Sample**
40
42
 
41
43
  ```typescript
@@ -110,6 +112,7 @@ const Sample = () => {
110
112
  );
111
113
  };
112
114
  ```
115
+
113
116
  <a id="mappers"></a>
114
117
 
115
118
  ## **Mappers**
@@ -245,7 +248,7 @@ const mapper = [
245
248
 
246
249
  <a id="form-group-context"></a>
247
250
 
248
- ## **Form Group Context**
251
+ ## **Form Group Context**
249
252
 
250
253
  <a id="formgroupcontextprovider"></a>
251
254
 
@@ -406,6 +409,7 @@ const FormComponent = (): React.ReactElement => {
406
409
 
407
410
  export default FormComponent;
408
411
  ```
412
+
409
413
  <a id="form"></a>
410
414
 
411
415
  ## **Form**
@@ -449,6 +453,7 @@ A simple example of rendering a basic form
449
453
  ```javascript
450
454
  <Form schema={schema} />
451
455
  ```
456
+
452
457
  <a id="submit-form"></a>
453
458
 
454
459
  ## **Submit Form**
@@ -621,6 +626,7 @@ Schema components contains the information of the component that will be rendere
621
626
  }]
622
627
  }
623
628
  ```
629
+
624
630
  <a id="formatters"></a>
625
631
 
626
632
  ## **formatters**
@@ -659,6 +665,7 @@ const formatters = {
659
665
  upperCase: true,
660
666
  };
661
667
  ```
668
+
662
669
  <a id="nametosubmit"></a>
663
670
 
664
671
  ## **nameToSubmit**
@@ -686,6 +693,7 @@ when calling the `onSubmit` or `onData` the field section of this field will out
686
693
  }
687
694
  }
688
695
  ```
696
+
689
697
  <a id="props"></a>
690
698
 
691
699
  ## **props**
@@ -813,6 +821,7 @@ Each config you opt to use, needs to be filled with an API configuration, the co
813
821
  | url | string | Request url ex: http://mockapi.org |
814
822
  | body? | Record<string, unknown> | Request body (only POST requests) |
815
823
  | headers? | OutgoingHttpHeaders | Avaliable HTTP headers |
824
+ | queryParams? | Record<string,string> | url query params (to be appended to the already existing ones) |
816
825
  | resultPath? | string | response dot notation path to the value needed from the response |
817
826
  | fallbackValue? | unknown | default value to return if the API returns error |
818
827
  | preConditions? | TSchemaValidation | validations to occur before the request is made (check validations section) |
@@ -904,6 +913,7 @@ const resetValues = [
904
913
  },
905
914
  ];
906
915
  ```
916
+
907
917
  <a id="visibilityconditions"></a>
908
918
 
909
919
  ## **visibilityConditions**
@@ -952,6 +962,46 @@ const visibilityConditions = [
952
962
  ];
953
963
  ```
954
964
 
965
+ <a id="resetpropertyvalues"></a>
966
+
967
+ ## **resetPropertyValues**
968
+
969
+ resetPropertyValues will change a property value based on validation rules
970
+
971
+ > WARNING: do not rely on this to make mutations on your properties, templating already is a powerful tool and with this you can destroy some schema configurations accidentaly, this is a last resort schema manipulation tool to solve some edge cases with API requests callbacks handling
972
+
973
+ | Prop | Type | Description |
974
+ | -------------- | -------------------------------------------- | -------------------------------------------------------------- |
975
+ | property | typeof ALLOWED_RESET_PROPS_MUTATIONS[number] | property to be changed, ex: api, resetValues, etc.. |
976
+ | path | string | path where the property to be changed is located |
977
+ | field | string | field that will recieve the property change |
978
+ | resettledValue | unknown | value to be replaced onto the property |
979
+ | validations | TSchemaValidation | validations rules to be validated to change the property value |
980
+ | events | Partial<TEvents>[] | events to listen to apply this change |
981
+
982
+ example:
983
+
984
+ this will change the `api.named.chuck` property onto field `postalCode` when the `ON_FIELD_CHANGE` event occurs,
985
+ will change the content to: `{ status: null, response: ''}`
986
+
987
+ ```typescript
988
+ resetPropertyValues: [
989
+ {
990
+ property: 'api',
991
+ path: 'named.chuck',
992
+ events: ['ON_FIELD_CHANGE'],
993
+ field: 'postalCode',
994
+ resettledValue: {
995
+ status: null,
996
+ response: '',
997
+ },
998
+ validations: {
999
+ bool: false,
1000
+ },
1001
+ },
1002
+ ],
1003
+ ```
1004
+
955
1005
  <a id="templating"></a>
956
1006
 
957
1007
  ## **templating**
package/index.esm.js CHANGED
@@ -2499,6 +2499,7 @@ function Form({
2499
2499
  iVars,
2500
2500
  action,
2501
2501
  method,
2502
+ config,
2502
2503
  onSubmit,
2503
2504
  onFormMount,
2504
2505
  onData,
@@ -2518,7 +2519,8 @@ function Form({
2518
2519
  removeForm,
2519
2520
  getForm,
2520
2521
  mappers,
2521
- debugMode
2522
+ debugMode,
2523
+ formGroupInstance
2522
2524
  } = useFormGroupContext({});
2523
2525
  const [tree, setTree] = useState();
2524
2526
  const schemaIndex = useMemo(() => index || (schema === null || schema === void 0 ? void 0 : schema.index) || 'defaultChange', [index, schema]);
@@ -2536,7 +2538,8 @@ function Form({
2536
2538
  action: action || (schema === null || schema === void 0 ? void 0 : schema.action),
2537
2539
  method: method || (schema === null || schema === void 0 ? void 0 : schema.method),
2538
2540
  index: schemaIndex,
2539
- mappers
2541
+ mappers,
2542
+ config: config || formGroupInstance.config
2540
2543
  });
2541
2544
  addForm({
2542
2545
  key: schemaIndex,
@@ -2594,18 +2597,9 @@ function Form({
2594
2597
  * initialValues setter for async initialValues
2595
2598
  */
2596
2599
  useEffect(() => {
2597
- const form = getForm({
2600
+ if (initialValues) getForm({
2598
2601
  key: schemaIndex
2599
- });
2600
- if (initialValues && form) {
2601
- Object.keys(initialValues).forEach(fieldName => {
2602
- var _a;
2603
- (_a = form.fields.get(fieldName)) === null || _a === void 0 ? void 0 : _a.emitValue({
2604
- event: 'ON_FIELD_MOUNT',
2605
- value: initialValues[fieldName]
2606
- });
2607
- });
2608
- }
2602
+ }).setInitialValues(initialValues);
2609
2603
  }, [initialValues]);
2610
2604
  /**
2611
2605
  * hook usage to keep event bindings updated on callback functions passed as props
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@bolttech/form-engine",
3
- "version": "3.0.1-beta.7",
3
+ "version": "3.0.2-beta.1",
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": "0.0.2-beta.7",
9
+ "@bolttech/form-engine-core": "0.0.3-beta.1",
10
10
  "react": "18.2.0",
11
11
  "rxjs": "7.8.1"
12
12
  },
@@ -5,5 +5,5 @@ import { TFormProps } from './Form.type';
5
5
  * @param {TFormProps} param form properties initializor
6
6
  * @returns {ReactElement}
7
7
  */
8
- declare function Form<T>({ schema, index, initialValues, iVars, action, method, onSubmit, onFormMount, onData, onBlur, onChange, onApiResponse, onClick, onFocus, onKeyDown, onKeyUp, onMount, onValid, children, }: TFormProps<T>): ReactElement;
8
+ declare function Form<T>({ schema, index, initialValues, iVars, action, method, config, onSubmit, onFormMount, onData, onBlur, onChange, onApiResponse, onClick, onFocus, onKeyDown, onKeyUp, onMount, onValid, children, }: TFormProps<T>): ReactElement;
9
9
  export default Form;