@bolttech/form-engine 3.0.2-beta.9 → 3.0.3
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 +247 -85
- package/index.d.ts +297 -0
- package/index.esm.js +2163 -1296
- package/package.json +11 -8
- package/index.esm.d.ts +0 -1
- package/src/components/AsFormField/AsFormField.d.ts +0 -13
- package/src/components/AsFormField/AsFormField.type.d.ts +0 -9
- package/src/components/AsFormFieldBuilder/AsFormFieldBuilder.d.ts +0 -11
- package/src/components/AsFormFieldBuilder/AsFormFieldBuilder.type.d.ts +0 -20
- package/src/components/FieldWrapper/FieldWrapper.d.ts +0 -11
- package/src/components/FieldWrapper/FieldWrapper.type.d.ts +0 -28
- package/src/components/Form/Form.d.ts +0 -9
- package/src/components/Form/Form.type.d.ts +0 -11
- package/src/components/index.d.ts +0 -3
- package/src/context/FormGroupContext.d.ts +0 -19
- package/src/context/FormGroupContext.type.d.ts +0 -48
- package/src/generators/formBuilder.d.ts +0 -26
- package/src/helpers/helpers.d.ts +0 -7
- package/src/helpers/mapper.d.ts +0 -7
- package/src/hooks/index.d.ts +0 -2
- package/src/hooks/useForm/useForm.d.ts +0 -7
- package/src/hooks/useForm/useForm.type.d.ts +0 -12
- package/src/hooks/useFormGroup/useFormGroup.d.ts +0 -4
- package/src/hooks/useFormGroup/useFormGroup.type.d.ts +0 -17
- package/src/index.d.ts +0 -5
- package/src/types/index.d.ts +0 -32
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)
|
|
@@ -25,6 +25,8 @@ This is an adapter to be used with the bolttech form engine. Compatible with Nex
|
|
|
25
25
|
- 6.7 [resetValues](#resetvalues)
|
|
26
26
|
- 6.8 [visibilityConditions](#visibilityconditions)
|
|
27
27
|
- 6.9 [resetPropertyValues](#resetpropertyvalues)
|
|
28
|
+
- 6.10 [visibility](#visibility)
|
|
29
|
+
- 6.11 [persistValue](#persistValue)
|
|
28
30
|
|
|
29
31
|
7. [templating](#templating)
|
|
30
32
|
|
|
@@ -35,6 +37,7 @@ This is an adapter to be used with the bolttech form engine. Compatible with Nex
|
|
|
35
37
|
|
|
36
38
|
9. [AsFormField](#asformfield)
|
|
37
39
|
10. [AsFormFieldBuilder](#asformfieldbuilder)
|
|
40
|
+
11. [AsFormFieldRepeater](#asformfieldrepeater)
|
|
38
41
|
|
|
39
42
|
<a id="sample"></a>
|
|
40
43
|
|
|
@@ -122,7 +125,7 @@ Mappers are the configuration that needs to be provided in order to use componen
|
|
|
122
125
|
The mapper configuration goes as it follows:
|
|
123
126
|
|
|
124
127
|
| Prop | Type | Description |
|
|
125
|
-
|
|
128
|
+
| ---------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
|
126
129
|
| componentName | string | name to be used onto schema to identify the component to be rendered on a field |
|
|
127
130
|
| events | TComponentPropsMapping | events mapping that will reference the component prop with the respective form-engine prop that will handle it's content |
|
|
128
131
|
| valueChangeEvent | TValueChangeEvent | component handle function to define how the value is extracted from the 'onChange' event of the component |
|
|
@@ -132,7 +135,7 @@ The mapper configuration goes as it follows:
|
|
|
132
135
|
`events` are optional and will reference component props that will provide it's dynamic behaviour:
|
|
133
136
|
|
|
134
137
|
| Prop | Type | Description |
|
|
135
|
-
|
|
138
|
+
| --------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
136
139
|
| getValue | string | component property that will contain the value |
|
|
137
140
|
| setValue | string | component property that handles onChange events triggered by the component |
|
|
138
141
|
| onBlur | string | component property that handles onBlur events triggered by the component |
|
|
@@ -419,33 +422,40 @@ After configuring the provider, `<Form />` components lets you render a form
|
|
|
419
422
|
|
|
420
423
|
### Props
|
|
421
424
|
|
|
422
|
-
| Prop | Type | Description
|
|
423
|
-
| ----------------------------------- | ---------------------------------------------------------------------------------- |
|
|
424
|
-
| [DEPRECIATED] disable | boolean | Disable all form inputs. It will use the default htm disable attribute
|
|
425
|
+
| Prop | Type | Description |
|
|
426
|
+
| ----------------------------------- | ---------------------------------------------------------------------------------- | ------------ |
|
|
427
|
+
| [DEPRECIATED] disable | boolean | Disable all form inputs. It will use the default htm disable attribute |
|
|
425
428
|
| [DEPRECIATED] group | string | Form group identifier. Used be able to group several forms and then get data with useGroupForm. One will be generated as default if omitted |
|
|
426
|
-
| index | string | Form identified. One will be generated as default if omitted
|
|
427
|
-
| [DEPRECIATED] hooks | THooks | Provide functions to run on certain life-cycle events
|
|
428
|
-
| iVars | Object | One object with internal variables to be used in form with data binding
|
|
429
|
-
| initialValues | Object | Object with form initial values that will map to a field.
|
|
430
|
-
| Schema | TSchema | Form Schema
|
|
431
|
-
| [DEPRECIATED] autoComplete | string | HTML autocomplete
|
|
432
|
-
| className | string | Allow to style form
|
|
433
|
-
| onSubmit | callback(TFormValues) | Will be called when there is a submit action in the form
|
|
434
|
-
| onData | callback(TFormData) | Will be called when any field data change. The arguments will let you know which field changed and the field configuration
|
|
435
|
-
| onBlur | callback(TFieldEvent) | Will be called when any field blured. The arguments will let you know which field blured and the field configuration
|
|
436
|
-
| onFocus | callback(TFieldEvent) | Will be called when any field focused change. The arguments will let you know which field focused and the field configuration
|
|
437
|
-
| onMount | callback(TFormValues,TComponent, TField) | Will be called when some field mounted. Its called with the field that information that mounted.
|
|
438
|
-
| [DEPRECIATED] onStep | callback(TFormValues) | Called when a form step changed
|
|
439
|
-
| [DEPRECIATED] onLog | callback(TLoggingEvent) | Called on each log, if the logging is enabled
|
|
440
|
-
| [DEPRECIATED] onScopeChange | onScopeChange?(scope: TScope, namespace: string, key: string): void; | Called everything scope change with the changing information (namespace and key) and the changed scope
|
|
441
|
-
| onClick | onClick(TFieldEvent) | Callback function that runs on each component click
|
|
442
|
-
| onApiResponse | onApiResponse(TFieldEvent) | Callback function that runs on each component after api call.
|
|
443
|
-
| [DEPRECIATED] onFieldRehydrate | onFieldRehydrate?(values: TFormValues, component: TComponent, field: TField): void | This callback is called whenever some form field was rehydrated
|
|
444
|
-
| [DEPRECIATED] renderLoading | renderLoading?(): ReactElement; | Component to render while the schema has not rendered
|
|
445
|
-
| [DEPRECIATED] onFormMount | onFormMount?(values: TFormValues): void; | Called when the form finished mounted
|
|
446
|
-
| [DEPRECIATED] formattedDataDefaults | Object | Some default data to fields when they are undefined
|
|
447
|
-
| [DEPRECIATED] submitOnValidOnly | boolean | Boolean indicating if form can be submitted even if it is invalid
|
|
448
|
-
| [DEPRECIATED] renderFieldWrapper | renderFieldWrapper(component: TComponent, children: ReactElement[]) | Function that allows to insert a wrapper in place of a component or wrapping the component
|
|
429
|
+
| index | string | Form identified. One will be generated as default if omitted |
|
|
430
|
+
| [DEPRECIATED] hooks | THooks | Provide functions to run on certain life-cycle events |
|
|
431
|
+
| iVars | Object | One object with internal variables to be used in form with data binding |
|
|
432
|
+
| initialValues | Object | Object with form initial values that will map to a field. |
|
|
433
|
+
| Schema | TSchema | Form Schema |
|
|
434
|
+
| [DEPRECIATED] autoComplete | string | HTML autocomplete |
|
|
435
|
+
| className | string | Allow to style form |
|
|
436
|
+
| onSubmit | callback(TFormValues) | Will be called when there is a submit action in the form |
|
|
437
|
+
| onData | callback(TFormData) | Will be called when any field data change. The arguments will let you know which field changed and the field configuration |
|
|
438
|
+
| onBlur | callback(TFieldEvent) | Will be called when any field blured. The arguments will let you know which field blured and the field configuration |
|
|
439
|
+
| onFocus | callback(TFieldEvent) | Will be called when any field focused change. The arguments will let you know which field focused and the field configuration |
|
|
440
|
+
| onMount | callback(TFormValues,TComponent, TField) | Will be called when some field mounted. Its called with the field that information that mounted. |
|
|
441
|
+
| [DEPRECIATED] onStep | callback(TFormValues) | Called when a form step changed |
|
|
442
|
+
| [DEPRECIATED] onLog | callback(TLoggingEvent) | Called on each log, if the logging is enabled |
|
|
443
|
+
| [DEPRECIATED] onScopeChange | onScopeChange?(scope: TScope, namespace: string, key: string): void; | Called everything scope change with the changing information (namespace and key) and the changed scope |
|
|
444
|
+
| onClick | onClick(TFieldEvent) | Callback function that runs on each component click |
|
|
445
|
+
| onApiResponse | onApiResponse(TFieldEvent) | Callback function that runs on each component after api call. |
|
|
446
|
+
| [DEPRECIATED] onFieldRehydrate | onFieldRehydrate?(values: TFormValues, component: TComponent, field: TField): void | This callback is called whenever some form field was rehydrated |
|
|
447
|
+
| [DEPRECIATED] renderLoading | renderLoading?(): ReactElement; | Component to render while the schema has not rendered |
|
|
448
|
+
| [DEPRECIATED] onFormMount | onFormMount?(values: TFormValues): void; | Called when the form finished mounted |
|
|
449
|
+
| [DEPRECIATED] formattedDataDefaults | Object | Some default data to fields when they are undefined |
|
|
450
|
+
| [DEPRECIATED] submitOnValidOnly | boolean | Boolean indicating if form can be submitted even if it is invalid |
|
|
451
|
+
| [DEPRECIATED] renderFieldWrapper | renderFieldWrapper(component: TComponent, children: ReactElement[]) | Function that allows to insert a wrapper in place of a component or wrapping the component |
|
|
452
|
+
| onApiRequest | onApiRequest(TFieldEvent) | Callback function that runs when an api call starts |
|
|
453
|
+
| onChange | onFieldChange(TFieldEvent) | Callback function that runs on each component value changes
|
|
454
|
+
| onKeyDown | onKeyDown(TFieldEvent) | Callback function that runs on each key down event |
|
|
455
|
+
| onKeyUp | onKeyUp(TFieldEvent) | Callback function that runs on each key up event |
|
|
456
|
+
| onCleared | onCleared(TFieldEvent) | Callback function that runs on a value that has been changed by resetValues event |
|
|
457
|
+
| onUnmount | onUnmount(TFieldEvent) | Callback function that runs when a field is unmounted or hidden by a visibility condition rule (use with caution) |
|
|
458
|
+
|
|
449
459
|
|
|
450
460
|
### Example
|
|
451
461
|
|
|
@@ -521,15 +531,15 @@ have a `Form` component and event callback functions needs to be setted
|
|
|
521
531
|
|
|
522
532
|
Schema is the structure of the form, it will contain the logic to be rendered and configurations of the fields to apply dynamic logic
|
|
523
533
|
|
|
524
|
-
| Prop
|
|
525
|
-
|
|
|
526
|
-
| index
|
|
527
|
-
| action?
|
|
528
|
-
| method?
|
|
529
|
-
| config?
|
|
530
|
-
| initialValues? | Record<string, unknown> | initial values to be loaded on the form |
|
|
531
|
-
| iVars?
|
|
532
|
-
| components?
|
|
534
|
+
| Prop | Type | Description |
|
|
535
|
+
| ----------------------------------------------------------------------------------------------------------- | ----------------------- | ----------------------------------------------------------------------- |
|
|
536
|
+
| [index](../../docs/form-engine-core/src/interfaces/schema/interfaces/IFormSchema.md#index) | string | unique form id to handle multiple form on form group |
|
|
537
|
+
| [action](../../docs/form-engine-core/src/interfaces/schema/interfaces/IFormSchema.md#action)? | string | WIP: HTML form native action property to handle native form submissions |
|
|
538
|
+
| [method](../../docs/form-engine-core/src/interfaces/schema/interfaces/IFormSchema.md#method)? | string | WIP: HTML form native method property to handle native form submissions |
|
|
539
|
+
| [config](../../docs/form-engine-core/src/interfaces/schema/interfaces/IFormSchema.md#config)? | TSchemaFormConfig | Optional configuration object to set api and events debounce time |
|
|
540
|
+
| [initialValues](../../docs/form-engine-core/src/interfaces/schema/interfaces/IFormSchema.md#initialvalues)? | Record<string, unknown> | initial values to be loaded on the form |
|
|
541
|
+
| [iVars](../../docs/form-engine-core/src/interfaces/schema/interfaces/IFormSchema.md#ivars)? | Record<string, unknown> | dynamic values that can be changed externally to be used onto the form |
|
|
542
|
+
| [components](../../docs/form-engine-core/src/interfaces/schema/interfaces/IFormSchema.md#components)? | IComponentSchema[] | components to be rendered defined on the mappers |
|
|
533
543
|
|
|
534
544
|
this root configuration can be defined onto the `Form` component except the `components`
|
|
535
545
|
|
|
@@ -563,19 +573,19 @@ const schema: IFormSchema = {
|
|
|
563
573
|
|
|
564
574
|
Schema components contains the information of the component that will be rendered and the configurations he will exectute
|
|
565
575
|
|
|
566
|
-
| Prop
|
|
567
|
-
|
|
|
568
|
-
| component
|
|
569
|
-
| props?
|
|
570
|
-
| name
|
|
571
|
-
| nameToSubmit?
|
|
572
|
-
| validations?
|
|
573
|
-
| api?
|
|
574
|
-
| visibilityConditions? | TVisibility[] | visibilityConditions configuration described below |
|
|
575
|
-
| resetValues?
|
|
576
|
-
| formatters?
|
|
577
|
-
| masks?
|
|
578
|
-
| children?
|
|
576
|
+
| Prop | Type | Description |
|
|
577
|
+
| ------------------------------------------------------------------------------------------------------------------------------ | -------------------- | ------------------------------------------------------------------------------------------- |
|
|
578
|
+
| [component](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md#component) | string | component name defined on schema to render the correspondent component |
|
|
579
|
+
| [props](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md#props)? | TProps | props of the component ex: label |
|
|
580
|
+
| [name](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md#name) | string | unique id to identify the field onto form-engine |
|
|
581
|
+
| [nameToSubmit](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md#nametosubmit)? | string | dot notation to submit a custom path to the component value ex: 'person.profile.firstName' |
|
|
582
|
+
| [validations](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md#validations)? | TValidations | validations configuration described below |
|
|
583
|
+
| [api](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md#api)? | TApiEvent | api configuration described below |
|
|
584
|
+
| [visibilityConditions](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md#visibilityconditions)? | TVisibility[] | visibilityConditions configuration described below |
|
|
585
|
+
| [resetValues](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md#resetvalues)? | TResetValueMethods[] | resetValues configuration described below |
|
|
586
|
+
| [formatters](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md#formatters)? | TFormatters | formatters configuration described below |
|
|
587
|
+
| [masks](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md#masks)? | TMasks | masks configuration described below |
|
|
588
|
+
| [children](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md#children)? | IComponentSchema[] | nested components to be rendered (if the current parent component accepts child components) |
|
|
579
589
|
|
|
580
590
|
### Example
|
|
581
591
|
|
|
@@ -628,25 +638,54 @@ Schema components contains the information of the component that will be rendere
|
|
|
628
638
|
}
|
|
629
639
|
```
|
|
630
640
|
|
|
641
|
+
Check the [TSDocs](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md) from `IComponentSchema` on form-engine-core
|
|
642
|
+
|
|
631
643
|
<a id="formatters"></a>
|
|
632
644
|
|
|
633
645
|
## **formatters**
|
|
634
646
|
|
|
635
|
-
formatters are methods that will format the input inserted on any field, they will format a value, regardless the event type
|
|
647
|
+
formatters are methods that will format the input inserted on any field, they will format a value, regardless the event type.
|
|
648
|
+
|
|
649
|
+
| Prop | Type | Description |
|
|
650
|
+
| ------------------------------------------------------------------------------------------------------------ | ------------------------- | ---------------------------------------------------------------------------------------------------------------- |
|
|
651
|
+
| [callback](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#callback)? | (value) => void | Custom formatter callback function |
|
|
652
|
+
| [capitalize](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#capitalize)? | boolean | Capitalize the value |
|
|
653
|
+
| [dotEvery3chars](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#dotevery3chars)? | boolean | Add a dot every 3 characters |
|
|
654
|
+
| [gapsCreditCard](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#gapscreditcard) | string[] | Gaps to insert in credit card numbers |
|
|
655
|
+
| [maxLength](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#maxlength)? | number | Truncates the input value to a specified maximum length if necessary |
|
|
656
|
+
| [onlyFloatNumber](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#onlyfloatnumber)? | TCurrencyMask | Allow only float numbers with specific precision and decimal |
|
|
657
|
+
| [onlyLetters](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#onlyletters)? | boolean | Allow only letters |
|
|
658
|
+
| [onlyNumbers](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#onlynumbers)? | boolean | Allow only numbers |
|
|
659
|
+
| [regex](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#regex)? | string | Regular expression for formatting |
|
|
660
|
+
| [splitter](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#splitter)? | TSplitterFormatterValue[] | Splitter values for formatting |
|
|
661
|
+
| [trim](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#trim)? | boolean | Removes whitespace from both ends of this string and returns a new string, without modifying the original string |
|
|
662
|
+
| [uppercase](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#uppercase)? | boolean | Convert the value to uppercase |
|
|
636
663
|
|
|
637
664
|
### Avaliable formatters
|
|
638
665
|
|
|
639
|
-
Check the TSDocs from `TFormatters` on form-engine-core
|
|
666
|
+
Check the [TSDocs](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md) from `TFormatters` on form-engine-core
|
|
640
667
|
|
|
641
668
|
<a id="masks"></a>
|
|
642
669
|
|
|
643
670
|
## **masks**
|
|
644
671
|
|
|
645
|
-
masks are methods that will format the input inserted on any field, they will show to the user a formatted value, but the submission value will be the original input of the user
|
|
672
|
+
masks are methods that will format the input inserted on any field, they will show to the user a formatted value, but the submission value will be the original input of the user.
|
|
673
|
+
|
|
674
|
+
| Prop | Type | Description |
|
|
675
|
+
| --------------------------------------------------------------------------------------------------------- | ---------------------- | ------------------------------------------------------ |
|
|
676
|
+
| [card](../../docs/form-engine-core/src/types/schema/type-aliases/TMasks.md#card)? | boolean | Mask for card values |
|
|
677
|
+
| [cardDate](../../docs/form-engine-core/src/types/schema/type-aliases/TMasks.md#carddate)? | boolean | Mask for card date values |
|
|
678
|
+
| [currency](../../docs/form-engine-core/src/types/schema/type-aliases/TMasks.md#currency)? | TCurrencyMask | Mask for currency values |
|
|
679
|
+
| [custom](../../docs/form-engine-core/src/types/schema/type-aliases/TMasks.md#custom) | string | Custom mask pattern |
|
|
680
|
+
| [fein](../../docs/form-engine-core/src/types/schema/type-aliases/TMasks.md#fein)? | boolean | Mask for FEIN (Federal Employer Identification Number) |
|
|
681
|
+
| [generic](../../docs/form-engine-core/src/types/schema/type-aliases/TMasks.md#generic)? | TMaskGeneric[] | Array of generic masks |
|
|
682
|
+
| [replaceAll](../../docs/form-engine-core/src/types/schema/type-aliases/TMasks.md#replaceall)? | string | Value to replace all matches |
|
|
683
|
+
| [secureCreditCard](../../docs/form-engine-core/src/types/schema/type-aliases/TMasks.md#securecreditcard)? | boolean | Mask for securing credit card values |
|
|
684
|
+
| [callback](../../docs/form-engine-core/src/types/schema/type-aliases/TMasks.md#callback)? | (value, masks) => void | Custom mask callback function |
|
|
646
685
|
|
|
647
686
|
### Avaliable masks
|
|
648
687
|
|
|
649
|
-
Check the TSDocs from `TMasks` on form-engine-core
|
|
688
|
+
Check the [TSDocs](../../docs/form-engine-core/src/types/schema/type-aliases/TMasks.md) from `TMasks` on form-engine-core
|
|
650
689
|
|
|
651
690
|
### From v2 to v3
|
|
652
691
|
|
|
@@ -729,7 +768,7 @@ validations let you set rules in order to validate a field, then show errorMessa
|
|
|
729
768
|
|
|
730
769
|
### Avaliable validations
|
|
731
770
|
|
|
732
|
-
Check the TSDocs from `TValidationMethods` on form-engine-core
|
|
771
|
+
Check the [TSDocs](../../docs/form-engine-core/src/types/schema/type-aliases/TValidationMethods.md) from `TValidationMethods` on form-engine-core
|
|
733
772
|
|
|
734
773
|
### From v2 to v3
|
|
735
774
|
|
|
@@ -816,18 +855,18 @@ The configuration is as it follows:
|
|
|
816
855
|
|
|
817
856
|
Each config you opt to use, needs to be filled with an API configuration, the configuration is as it follows:
|
|
818
857
|
|
|
819
|
-
| Prop
|
|
820
|
-
|
|
|
821
|
-
| method
|
|
822
|
-
| url
|
|
823
|
-
| body?
|
|
824
|
-
| headers?
|
|
825
|
-
| queryParams?
|
|
826
|
-
| resultPath?
|
|
827
|
-
| fallbackValue?
|
|
828
|
-
| preConditions?
|
|
829
|
-
| blockRequestWhenInvalid? | boolean | flag to only request the api config if the field is valid |
|
|
830
|
-
| transform?
|
|
858
|
+
| Prop | Type | Description |
|
|
859
|
+
| --------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | ------------------------------------------------------------------------------------- |
|
|
860
|
+
| [method](../../docs/form-engine-core/src/types/schema/type-aliases/TApiConfig.md#method) | 'GET' or 'POST' | HTTP method (only GET or POST) |
|
|
861
|
+
| [url](../../docs/form-engine-core/src/types/schema/type-aliases/TApiConfig.md#url) | string | Request url ex: http://mockapi.org |
|
|
862
|
+
| [body](../../docs/form-engine-core/src/types/schema/type-aliases/TApiConfig.md#body)? | Record<string, unknown> | Request body (only POST requests) |
|
|
863
|
+
| [headers](../../docs/form-engine-core/src/types/schema/type-aliases/TApiConfig.md#headers)? | OutgoingHttpHeaders | Avaliable HTTP headers |
|
|
864
|
+
| [queryParams](../../docs/form-engine-core/src/types/schema/type-aliases/TApiConfig.md#queryparams)? | Record<string,string> | url query params (to be appended to the already existing ones) |
|
|
865
|
+
| [resultPath](../../docs/form-engine-core/src/types/schema/type-aliases/TApiConfig.md#resultpath)? | string | response dot notation path to the value needed from the response |
|
|
866
|
+
| [fallbackValue](../../docs/form-engine-core/src/types/schema/type-aliases/TApiConfig.md#fallbackvalue)? | unknown | default value to return if the API returns error |
|
|
867
|
+
| [preConditions](../../docs/form-engine-core/src/types/schema/type-aliases/TApiConfig.md#preconditions)? | TSchemaValidation | validations to occur before the request is made (check validations section) |
|
|
868
|
+
| [blockRequestWhenInvalid](../../docs/form-engine-core/src/types/schema/type-aliases/TApiConfig.md#blockrequestwheninvalid)? | boolean | flag to only request the api config if the field is valid |
|
|
869
|
+
| [transform](../../docs/form-engine-core/src/types/schema/type-aliases/TApiConfig.md#transform)? | { callback:(payload) => unknown } | custom function to be passed as callback to transform the request in any other format |
|
|
831
870
|
|
|
832
871
|
### From v2 to v3
|
|
833
872
|
|
|
@@ -867,7 +906,7 @@ const api = {
|
|
|
867
906
|
};
|
|
868
907
|
```
|
|
869
908
|
|
|
870
|
-
the API result is commonly used with `templating`, check [templating](#
|
|
909
|
+
the API result is commonly used with `templating`, check [templating](#templating) section
|
|
871
910
|
|
|
872
911
|
<a id="resetvalues"></a>
|
|
873
912
|
|
|
@@ -875,14 +914,14 @@ the API result is commonly used with `templating`, check [templating](#markdown-
|
|
|
875
914
|
|
|
876
915
|
resetValues lets you change input values with the same rules as validations
|
|
877
916
|
|
|
878
|
-
| Prop
|
|
879
|
-
|
|
|
880
|
-
| validations
|
|
881
|
-
| fields
|
|
882
|
-
| events
|
|
883
|
-
| resettledValue
|
|
917
|
+
| Prop | Type | Description |
|
|
918
|
+
| --------------------------------------------------------------------------------------------- | -------------------- | ---------------------------------------------------------------------------------- |
|
|
919
|
+
| [validations](../../docs/form-engine-core/src/types/schema/type-aliases/TSchemaValidation.md) | TSchemaValidation | validations rules to be validated to reset the value to the configuration provided |
|
|
920
|
+
| fields | string[] or string | field or fields that will recieve the resettled value |
|
|
921
|
+
| events | Partial<TEvents>[] | events that will trigger the validation |
|
|
922
|
+
| resettledValue | unknown[] or unknown | value or values to be set on the specified fields |
|
|
884
923
|
|
|
885
|
-
if the event occurs and all the validations returns `true` the resettled value will trigger and the `fields` specified will be filled with the `resettledValue` values
|
|
924
|
+
if the event occurs and all the validations returns `true` the resettled value will trigger and the `fields` specified will be filled with the `resettledValue` values, also, the event ON_FIELD_CLEARED is triggered on the fields that gets the resettled value instead of ON_FIELD_CHANGE.
|
|
886
925
|
|
|
887
926
|
### from v2 to v3
|
|
888
927
|
|
|
@@ -1000,9 +1039,21 @@ resetPropertyValues: [
|
|
|
1000
1039
|
bool: false,
|
|
1001
1040
|
},
|
|
1002
1041
|
},
|
|
1003
|
-
]
|
|
1042
|
+
];
|
|
1004
1043
|
```
|
|
1005
1044
|
|
|
1045
|
+
<a id="visibility"></a>
|
|
1046
|
+
|
|
1047
|
+
## **visibility**
|
|
1048
|
+
|
|
1049
|
+
visibility prop is used to initiate the component with an initial visibility flag, before visibilityConditions take place, used on SSR
|
|
1050
|
+
|
|
1051
|
+
<a id="persistValue"></a>
|
|
1052
|
+
|
|
1053
|
+
## **persistValue**
|
|
1054
|
+
|
|
1055
|
+
persistValue is a flag that deremines if the field gets hidden, the moment it comes back visible, it will hold the previous value or not
|
|
1056
|
+
|
|
1006
1057
|
<a id="templating"></a>
|
|
1007
1058
|
|
|
1008
1059
|
## **templating**
|
|
@@ -1090,9 +1141,12 @@ The avalialbe callback methods are:
|
|
|
1090
1141
|
| onFocus | TFieldEvent | same as above |
|
|
1091
1142
|
| onKeyDown | TFieldEvent | same as above |
|
|
1092
1143
|
| onKeyUp | TFieldEvent | same as above |
|
|
1093
|
-
| onMount | TFieldEvent | same as above |
|
|
1094
|
-
| onApiResponse | TFieldEvent | same as above |
|
|
1095
1144
|
| onClick | TFieldEvent | same as above |
|
|
1145
|
+
| onApiResponse | TFieldEvent | event occuring when a api response is ready |
|
|
1146
|
+
| onApiRequest | TFieldEvent | event occuring when a api resquest is started |
|
|
1147
|
+
| onMount | TFieldEvent | event occuring when a field is mounted or set visible |
|
|
1148
|
+
| onUnmount | TFieldEvent | event occuring when a field is unmounted or hidden |
|
|
1149
|
+
| onCleared | TFieldEvent | event occuring when the field value is set with resetValues |
|
|
1096
1150
|
| onFormMount | TFormValues<T> | event occuring on form mount |
|
|
1097
1151
|
| onData | TFormData<T> | event occuring when a value is changing via input or logic |
|
|
1098
1152
|
| onSubmit | TFormValues<T> | event occuring when pressing the submit button defined on the form |
|
|
@@ -1109,7 +1163,7 @@ useFormGroup({ ids: ['form1', 'form2'], onData: (payload) => console.log(payload
|
|
|
1109
1163
|
As `useForm`, `useFormGroup` serves the same purpose, but the difference is that it handles multiple forms and has limited callback functions to set:
|
|
1110
1164
|
|
|
1111
1165
|
| method | payload | description |
|
|
1112
|
-
|
|
1166
|
+
| -------- | --------------------------------- | ----------------------------------------------------------- |
|
|
1113
1167
|
| onData | TFormGroupOnDataEventPayload<T> | event occurring when a value is changing via input or logic |
|
|
1114
1168
|
| onValid | TFormGroupOnValidEventPayload | event occurring when validation status changes on the form |
|
|
1115
1169
|
| onSubmit | TFormGroupOnSubmitEventPayload<T> | event occurring when form submission is trigger |
|
|
@@ -1167,8 +1221,116 @@ Ex:
|
|
|
1167
1221
|
|
|
1168
1222
|
Other than schema component properties like `validations`, `api`, etc.., it has additional properties to define the component, the associated form id and the name
|
|
1169
1223
|
|
|
1170
|
-
| method | type | description
|
|
1171
|
-
| --------- | ---------- |
|
|
1172
|
-
| mapper | TMapper<T> | mapper configuration to define the component
|
|
1173
|
-
| name | string | field name to be identified on the form
|
|
1174
|
-
| formIndex | string | index of the form to be identified on the formGroup
|
|
1224
|
+
| method | type | description |
|
|
1225
|
+
| --------- | ---------- | ------------------------------------------------------------------------------------------------------------------------ |
|
|
1226
|
+
| mapper | TMapper<T> | mapper configuration to define the component |
|
|
1227
|
+
| name | string | field name to be identified on the form |
|
|
1228
|
+
| formIndex | string | index of the form to be identified on the formGroup |
|
|
1229
|
+
| component | string | if mappers is provided from the formgroup context, you can assign the mapper by it's name instead of whole mapper config |
|
|
1230
|
+
|
|
1231
|
+
<a id="asformfieldrepeater"></a>
|
|
1232
|
+
|
|
1233
|
+
## **AsFormFieldRepeater**
|
|
1234
|
+
|
|
1235
|
+
Component adapter to aid managing multiple forms that shares the same inputs
|
|
1236
|
+
|
|
1237
|
+
Props:
|
|
1238
|
+
|
|
1239
|
+
| Attr | Type | Description |
|
|
1240
|
+
| ----------------- | --------------------------------------------------------- | -------------------------------------------------------------------------- |
|
|
1241
|
+
| RepeaterComponent | ElementType<{ formIndex: string }> | Component with form schema or AsFormFieldBuilder elements |
|
|
1242
|
+
| addFieldName | string | name of the button in the RepeaterComponent to add forms |
|
|
1243
|
+
| removeFieldName | string | name of the button in the RepeaterComponent to remove forms |
|
|
1244
|
+
| existingElements | Record<string, unknown>[] | existing values emmitted from stateUpdater to restore previous used values |
|
|
1245
|
+
| initialElements | number | elements to be pre-rendered when the form is presented |
|
|
1246
|
+
| stateUpdater | (payload: TFormGroupOnDataEventPayload<unknown>) => void; | callback function that reacts to RepeaterComponet values changes |
|
|
1247
|
+
| formPrefix | string | prefix for form names ex, prefix: foo, forms: ["foo1","foo2","foo3"] |
|
|
1248
|
+
| RepeaterFooter | ElementType<{ formIndex: string }> | Component with a button to add forms on the last position |
|
|
1249
|
+
|
|
1250
|
+
Common use case for this Adapter is to manage multiple forms that collects the same data ex: multiple person personal data
|
|
1251
|
+
|
|
1252
|
+
# Example
|
|
1253
|
+
|
|
1254
|
+
## RepeaterComponent
|
|
1255
|
+
|
|
1256
|
+
```javascript
|
|
1257
|
+
const FormElement = ({ formIndex }: { formIndex: string }) => {
|
|
1258
|
+
return (
|
|
1259
|
+
<>
|
|
1260
|
+
<AsFormFieldBuilder formIndex={formIndex} name="foo" component="input" props={{ label: 'foo' }} />
|
|
1261
|
+
<AsFormFieldBuilder formIndex={formIndex} name="bar" component="input" props={{ label: 'bar' }} />
|
|
1262
|
+
<AsFormFieldBuilder
|
|
1263
|
+
formIndex={formIndex}
|
|
1264
|
+
name="addForm"
|
|
1265
|
+
component="button"
|
|
1266
|
+
props={{
|
|
1267
|
+
text: 'add element',
|
|
1268
|
+
}}
|
|
1269
|
+
/>
|
|
1270
|
+
<AsFormFieldBuilder
|
|
1271
|
+
formIndex={formIndex}
|
|
1272
|
+
name="removeForm"
|
|
1273
|
+
component="button"
|
|
1274
|
+
props={{
|
|
1275
|
+
text: 'remove element',
|
|
1276
|
+
}}
|
|
1277
|
+
/>
|
|
1278
|
+
</>
|
|
1279
|
+
);
|
|
1280
|
+
};
|
|
1281
|
+
```
|
|
1282
|
+
|
|
1283
|
+
Important notes when developing this component is that it needs to receive an object with a key **formIndex**
|
|
1284
|
+
|
|
1285
|
+
Optionally, but to add form management functionality, add two buttons with **ON_FIELD_CLICK** event capture (can't be of type submit)
|
|
1286
|
+
both that Field button names will be needed on the next step
|
|
1287
|
+
|
|
1288
|
+
## RepeaterFooter
|
|
1289
|
+
|
|
1290
|
+
Optionally, you can develop a footer component with a button that will be added the bottom of the repeated forms
|
|
1291
|
+
and when you press that button will add a form at the bottom of the list
|
|
1292
|
+
|
|
1293
|
+
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)
|
|
1294
|
+
Note: the button name needs to be different from the names you gave to the buttons you are passing on the RepeaterComponent
|
|
1295
|
+
|
|
1296
|
+
```javascript
|
|
1297
|
+
const FormElementFooter = ({ formIndex }: { formIndex: string }) => {
|
|
1298
|
+
return (
|
|
1299
|
+
<AsFormFieldBuilder
|
|
1300
|
+
formIndex={formIndex}
|
|
1301
|
+
name="addFormBelow"
|
|
1302
|
+
component="button"
|
|
1303
|
+
props={{
|
|
1304
|
+
text: 'add element below',
|
|
1305
|
+
}}
|
|
1306
|
+
/>
|
|
1307
|
+
);
|
|
1308
|
+
};
|
|
1309
|
+
```
|
|
1310
|
+
|
|
1311
|
+
## AsFormFieldRepeater
|
|
1312
|
+
|
|
1313
|
+
Set the AsFormFieldRepeater adapter with the element you created above and the names that you gave to the button fields
|
|
1314
|
+
|
|
1315
|
+
```javascript
|
|
1316
|
+
<AsFormFieldRepeater
|
|
1317
|
+
RepeaterComponent={FormElement}
|
|
1318
|
+
RepeaterFooter={FormElementFooter}
|
|
1319
|
+
addFieldName="addForm"
|
|
1320
|
+
removeFieldName="removeForm"
|
|
1321
|
+
formPrefix="insured"
|
|
1322
|
+
stateUpdater={(payload) => {
|
|
1323
|
+
console.log(payload);
|
|
1324
|
+
}}
|
|
1325
|
+
/>
|
|
1326
|
+
```
|
|
1327
|
+
|
|
1328
|
+
**RepeaterComponent** and **RepeaterFooter** you set the elements created above
|
|
1329
|
+
|
|
1330
|
+
**addFieldName** you set the name to the button that will add a form on the position it's being clicked
|
|
1331
|
+
|
|
1332
|
+
**removeFieldName** you set the name to the button that will remove a form on the position it's being clicked
|
|
1333
|
+
|
|
1334
|
+
**formPrefix** the prefix for the forms emmited on **stateUpdater** enumerated
|
|
1335
|
+
|
|
1336
|
+
**stateUpdater** callback function that will receive the form values (similar to onData)
|