@bolttech/form-engine 3.1.1-beta.2 → 3.1.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
@@ -1,6 +1,6 @@
1
1
  # Form Engine React Adapter
2
2
 
3
- This is an adapter to be used with the bolttech form engine. Compatible with Next.js 13 and 14 and react 18.
3
+ This is an adapter to be used with the bolttech form engine. Compatible with Next.js 13, 14 and 15 (App Router SSR supported), React 18 and 19.
4
4
 
5
5
  1. [Sample](#sample)
6
6
  2. [mappers](#mappers)
@@ -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] (#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,8 @@ 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)
41
+ 12. [Server-Side Rendering (SSR)](#ssr)
40
42
 
41
43
  <a id="sample"></a>
42
44
 
@@ -124,7 +126,7 @@ Mappers are the configuration that needs to be provided in order to use componen
124
126
  The mapper configuration goes as it follows:
125
127
 
126
128
  | Prop | Type | Description |
127
- |------------------|------------------------|--------------------------------------------------------------------------------------------------------------------------|
129
+ | ---------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------ |
128
130
  | componentName | string | name to be used onto schema to identify the component to be rendered on a field |
129
131
  | events | TComponentPropsMapping | events mapping that will reference the component prop with the respective form-engine prop that will handle it's content |
130
132
  | valueChangeEvent | TValueChangeEvent | component handle function to define how the value is extracted from the 'onChange' event of the component |
@@ -134,7 +136,7 @@ The mapper configuration goes as it follows:
134
136
  `events` are optional and will reference component props that will provide it's dynamic behaviour:
135
137
 
136
138
  | Prop | Type | Description |
137
- |-----------------|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
139
+ | --------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
138
140
  | getValue | string | component property that will contain the value |
139
141
  | setValue | string | component property that handles onChange events triggered by the component |
140
142
  | onBlur | string | component property that handles onBlur events triggered by the component |
@@ -421,33 +423,40 @@ After configuring the provider, `<Form />` components lets you render a form
421
423
 
422
424
  ### Props
423
425
 
424
- | Prop | Type | Description |
425
- | ----------------------------------- | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
426
- | [DEPRECIATED] disable | boolean | Disable all form inputs. It will use the default htm disable attribute |
426
+ | Prop | Type | Description |
427
+ | ----------------------------------- | ---------------------------------------------------------------------------------- | ------------ |
428
+ | [DEPRECIATED] disable | boolean | Disable all form inputs. It will use the default htm disable attribute |
427
429
  | [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 |
428
- | index | string | Form identified. One will be generated as default if omitted |
429
- | [DEPRECIATED] hooks | THooks | Provide functions to run on certain life-cycle events |
430
- | iVars | Object | One object with internal variables to be used in form with data binding |
431
- | initialValues | Object | Object with form initial values that will map to a field. |
432
- | Schema | TSchema | Form Schema |
433
- | [DEPRECIATED] autoComplete | string | HTML autocomplete |
434
- | className | string | Allow to style form |
435
- | onSubmit | callback(TFormValues) | Will be called when there is a submit action in the form |
436
- | onData | callback(TFormData) | Will be called when any field data change. The arguments will let you know which field changed and the field configuration |
437
- | onBlur | callback(TFieldEvent) | Will be called when any field blured. The arguments will let you know which field blured and the field configuration |
438
- | onFocus | callback(TFieldEvent) | Will be called when any field focused change. The arguments will let you know which field focused and the field configuration |
439
- | onMount | callback(TFormValues,TComponent, TField) | Will be called when some field mounted. Its called with the field that information that mounted. |
440
- | [DEPRECIATED] onStep | callback(TFormValues) | Called when a form step changed |
441
- | [DEPRECIATED] onLog | callback(TLoggingEvent) | Called on each log, if the logging is enabled |
442
- | [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 |
443
- | onClick | onClick(TFieldEvent) | Callback function that runs on each component click |
444
- | onApiResponse | onApiResponse(TFieldEvent) | Callback function that runs on each component after api call. |
445
- | [DEPRECIATED] onFieldRehydrate | onFieldRehydrate?(values: TFormValues, component: TComponent, field: TField): void | This callback is called whenever some form field was rehydrated |
446
- | [DEPRECIATED] renderLoading | renderLoading?(): ReactElement; | Component to render while the schema has not rendered |
447
- | [DEPRECIATED] onFormMount | onFormMount?(values: TFormValues): void; | Called when the form finished mounted |
448
- | [DEPRECIATED] formattedDataDefaults | Object | Some default data to fields when they are undefined |
449
- | [DEPRECIATED] submitOnValidOnly | boolean | Boolean indicating if form can be submitted even if it is invalid |
450
- | [DEPRECIATED] renderFieldWrapper | renderFieldWrapper(component: TComponent, children: ReactElement[]) | Function that allows to insert a wrapper in place of a component or wrapping the component |
430
+ | index | string | Form identified. One will be generated as default if omitted |
431
+ | [DEPRECIATED] hooks | THooks | Provide functions to run on certain life-cycle events |
432
+ | iVars | Object | One object with internal variables to be used in form with data binding |
433
+ | initialValues | Object | Object with form initial values that will map to a field. |
434
+ | Schema | TSchema | Form Schema |
435
+ | [DEPRECIATED] autoComplete | string | HTML autocomplete |
436
+ | className | string | Allow to style form |
437
+ | onSubmit | callback(TFormValues) | Will be called when there is a submit action in the form |
438
+ | onData | callback(TFormData) | Will be called when any field data change. The arguments will let you know which field changed and the field configuration |
439
+ | onBlur | callback(TFieldEvent) | Will be called when any field blured. The arguments will let you know which field blured and the field configuration |
440
+ | onFocus | callback(TFieldEvent) | Will be called when any field focused change. The arguments will let you know which field focused and the field configuration |
441
+ | onMount | callback(TFormValues,TComponent, TField) | Will be called when some field mounted. Its called with the field that information that mounted. |
442
+ | [DEPRECIATED] onStep | callback(TFormValues) | Called when a form step changed |
443
+ | [DEPRECIATED] onLog | callback(TLoggingEvent) | Called on each log, if the logging is enabled |
444
+ | [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 |
445
+ | onClick | onClick(TFieldEvent) | Callback function that runs on each component click |
446
+ | onApiResponse | onApiResponse(TFieldEvent) | Callback function that runs on each component after api call. |
447
+ | [DEPRECIATED] onFieldRehydrate | onFieldRehydrate?(values: TFormValues, component: TComponent, field: TField): void | This callback is called whenever some form field was rehydrated |
448
+ | [DEPRECIATED] renderLoading | renderLoading?(): ReactElement; | Component to render while the schema has not rendered |
449
+ | [DEPRECIATED] onFormMount | onFormMount?(values: TFormValues): void; | Called when the form finished mounted |
450
+ | [DEPRECIATED] formattedDataDefaults | Object | Some default data to fields when they are undefined |
451
+ | [DEPRECIATED] submitOnValidOnly | boolean | Boolean indicating if form can be submitted even if it is invalid |
452
+ | [DEPRECIATED] renderFieldWrapper | renderFieldWrapper(component: TComponent, children: ReactElement[]) | Function that allows to insert a wrapper in place of a component or wrapping the component |
453
+ | onApiRequest | onApiRequest(TFieldEvent) | Callback function that runs when an api call starts |
454
+ | onChange | onFieldChange(TFieldEvent) | Callback function that runs on each component value changes
455
+ | onKeyDown | onKeyDown(TFieldEvent) | Callback function that runs on each key down event |
456
+ | onKeyUp | onKeyUp(TFieldEvent) | Callback function that runs on each key up event |
457
+ | onCleared | onCleared(TFieldEvent) | Callback function that runs on a value that has been changed by resetValues event |
458
+ | onUnmount | onUnmount(TFieldEvent) | Callback function that runs when a field is unmounted or hidden by a visibility condition rule (use with caution) |
459
+
451
460
 
452
461
  ### Example
453
462
 
@@ -523,15 +532,15 @@ have a `Form` component and event callback functions needs to be setted
523
532
 
524
533
  Schema is the structure of the form, it will contain the logic to be rendered and configurations of the fields to apply dynamic logic
525
534
 
526
- | Prop | Type | Description |
527
- | -------------- | ----------------------- | ----------------------------------------------------------------------- |
528
- | index | string | unique form id to handle multiple form on form group |
529
- | action? | string | WIP: HTML form native action property to handle native form submissions |
530
- | method? | string | WIP: HTML form native method property to handle native form submissions |
531
- | config? | TSchemaFormConfig | Optional configuration object to set api and events debounce time |
532
- | initialValues? | Record<string, unknown> | initial values to be loaded on the form |
533
- | iVars? | Record<string, unknown> | dynamic values that can be changed externally to be used onto the form |
534
- | components? | IComponentSchema[] | components to be rendered defined on the mappers |
535
+ | Prop | Type | Description |
536
+ | ----------------------------------------------------------------------------------------------------------- | ----------------------- | ----------------------------------------------------------------------- |
537
+ | [index](../../docs/form-engine-core/src/interfaces/schema/interfaces/IFormSchema.md#index) | string | unique form id to handle multiple form on form group |
538
+ | [action](../../docs/form-engine-core/src/interfaces/schema/interfaces/IFormSchema.md#action)? | string | WIP: HTML form native action property to handle native form submissions |
539
+ | [method](../../docs/form-engine-core/src/interfaces/schema/interfaces/IFormSchema.md#method)? | string | WIP: HTML form native method property to handle native form submissions |
540
+ | [config](../../docs/form-engine-core/src/interfaces/schema/interfaces/IFormSchema.md#config)? | TSchemaFormConfig | Optional configuration object to set api and events debounce time |
541
+ | [initialValues](../../docs/form-engine-core/src/interfaces/schema/interfaces/IFormSchema.md#initialvalues)? | Record<string, unknown> | initial values to be loaded on the form |
542
+ | [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 |
543
+ | [components](../../docs/form-engine-core/src/interfaces/schema/interfaces/IFormSchema.md#components)? | IComponentSchema[] | components to be rendered defined on the mappers |
535
544
 
536
545
  this root configuration can be defined onto the `Form` component except the `components`
537
546
 
@@ -565,19 +574,19 @@ const schema: IFormSchema = {
565
574
 
566
575
  Schema components contains the information of the component that will be rendered and the configurations he will exectute
567
576
 
568
- | Prop | Type | Description |
569
- | --------------------- | -------------------- | ------------------------------------------------------------------------------------------- |
570
- | component | string | component name defined on schema to render the correspondent component |
571
- | props? | TProps | props of the component ex: label |
572
- | name | string | unique id to identify the field onto form-engine |
573
- | nameToSubmit? | string | dot notation to submit a custom path to the component value ex: 'person.profile.firstName' |
574
- | validations? | TValidations | validations configuration described below |
575
- | api? | TApiEvent | api configuration described below |
576
- | visibilityConditions? | TVisibility[] | visibilityConditions configuration described below |
577
- | resetValues? | TResetValueMethods[] | resetValues configuration described below |
578
- | formatters? | TFormatters | formatters configuration described below |
579
- | masks? | TMasks | masks configuration described below |
580
- | children? | IComponentSchema[] | nested components to be rendered (if the current parent component accepts child components) |
577
+ | Prop | Type | Description |
578
+ | ------------------------------------------------------------------------------------------------------------------------------ | -------------------- | ------------------------------------------------------------------------------------------- |
579
+ | [component](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md#component) | string | component name defined on schema to render the correspondent component |
580
+ | [props](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md#props)? | TProps | props of the component ex: label |
581
+ | [name](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md#name) | string | unique id to identify the field onto form-engine |
582
+ | [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' |
583
+ | [validations](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md#validations)? | TValidations | validations configuration described below |
584
+ | [api](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md#api)? | TApiEvent | api configuration described below |
585
+ | [visibilityConditions](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md#visibilityconditions)? | TVisibility[] | visibilityConditions configuration described below |
586
+ | [resetValues](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md#resetvalues)? | TResetValueMethods[] | resetValues configuration described below |
587
+ | [formatters](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md#formatters)? | TFormatters | formatters configuration described below |
588
+ | [masks](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md#masks)? | TMasks | masks configuration described below |
589
+ | [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) |
581
590
 
582
591
  ### Example
583
592
 
@@ -630,25 +639,54 @@ Schema components contains the information of the component that will be rendere
630
639
  }
631
640
  ```
632
641
 
642
+ Check the [TSDocs](../../docs/form-engine-core/src/interfaces/schema/interfaces/IComponentSchema.md) from `IComponentSchema` on form-engine-core
643
+
633
644
  <a id="formatters"></a>
634
645
 
635
646
  ## **formatters**
636
647
 
637
- formatters are methods that will format the input inserted on any field, they will format a value, regardless the event type,
648
+ formatters are methods that will format the input inserted on any field, they will format a value, regardless the event type.
649
+
650
+ | Prop | Type | Description |
651
+ | ------------------------------------------------------------------------------------------------------------ | ------------------------- | ---------------------------------------------------------------------------------------------------------------- |
652
+ | [callback](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#callback)? | (value) => void | Custom formatter callback function |
653
+ | [capitalize](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#capitalize)? | boolean | Capitalize the value |
654
+ | [dotEvery3chars](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#dotevery3chars)? | boolean | Add a dot every 3 characters |
655
+ | [gapsCreditCard](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#gapscreditcard) | string[] | Gaps to insert in credit card numbers |
656
+ | [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 |
657
+ | [onlyFloatNumber](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#onlyfloatnumber)? | TCurrencyMask | Allow only float numbers with specific precision and decimal |
658
+ | [onlyLetters](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#onlyletters)? | boolean | Allow only letters |
659
+ | [onlyNumbers](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#onlynumbers)? | boolean | Allow only numbers |
660
+ | [regex](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#regex)? | string | Regular expression for formatting |
661
+ | [splitter](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#splitter)? | TSplitterFormatterValue[] | Splitter values for formatting |
662
+ | [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 |
663
+ | [uppercase](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md#uppercase)? | boolean | Convert the value to uppercase |
638
664
 
639
665
  ### Avaliable formatters
640
666
 
641
- Check the TSDocs from `TFormatters` on form-engine-core
667
+ Check the [TSDocs](../../docs/form-engine-core/src/types/schema/type-aliases/TFormatters.md) from `TFormatters` on form-engine-core
642
668
 
643
669
  <a id="masks"></a>
644
670
 
645
671
  ## **masks**
646
672
 
647
- 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
+ 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.
674
+
675
+ | Prop | Type | Description |
676
+ | --------------------------------------------------------------------------------------------------------- | ---------------------- | ------------------------------------------------------ |
677
+ | [card](../../docs/form-engine-core/src/types/schema/type-aliases/TMasks.md#card)? | boolean | Mask for card values |
678
+ | [cardDate](../../docs/form-engine-core/src/types/schema/type-aliases/TMasks.md#carddate)? | boolean | Mask for card date values |
679
+ | [currency](../../docs/form-engine-core/src/types/schema/type-aliases/TMasks.md#currency)? | TCurrencyMask | Mask for currency values |
680
+ | [custom](../../docs/form-engine-core/src/types/schema/type-aliases/TMasks.md#custom) | string | Custom mask pattern |
681
+ | [fein](../../docs/form-engine-core/src/types/schema/type-aliases/TMasks.md#fein)? | boolean | Mask for FEIN (Federal Employer Identification Number) |
682
+ | [generic](../../docs/form-engine-core/src/types/schema/type-aliases/TMasks.md#generic)? | TMaskGeneric[] | Array of generic masks |
683
+ | [replaceAll](../../docs/form-engine-core/src/types/schema/type-aliases/TMasks.md#replaceall)? | string | Value to replace all matches |
684
+ | [secureCreditCard](../../docs/form-engine-core/src/types/schema/type-aliases/TMasks.md#securecreditcard)? | boolean | Mask for securing credit card values |
685
+ | [callback](../../docs/form-engine-core/src/types/schema/type-aliases/TMasks.md#callback)? | (value, masks) => void | Custom mask callback function |
648
686
 
649
687
  ### Avaliable masks
650
688
 
651
- Check the TSDocs from `TMasks` on form-engine-core
689
+ Check the [TSDocs](../../docs/form-engine-core/src/types/schema/type-aliases/TMasks.md) from `TMasks` on form-engine-core
652
690
 
653
691
  ### From v2 to v3
654
692
 
@@ -731,7 +769,7 @@ validations let you set rules in order to validate a field, then show errorMessa
731
769
 
732
770
  ### Avaliable validations
733
771
 
734
- Check the TSDocs from `TValidationMethods` on form-engine-core
772
+ Check the [TSDocs](../../docs/form-engine-core/src/types/schema/type-aliases/TValidationMethods.md) from `TValidationMethods` on form-engine-core
735
773
 
736
774
  ### From v2 to v3
737
775
 
@@ -818,18 +856,18 @@ The configuration is as it follows:
818
856
 
819
857
  Each config you opt to use, needs to be filled with an API configuration, the configuration is as it follows:
820
858
 
821
- | Prop | Type | Description |
822
- | ------------------------ | --------------------------------- | ------------------------------------------------------------------------------------- |
823
- | method | 'GET' or 'POST' | HTTP method (only GET or POST) |
824
- | url | string | Request url ex: http://mockapi.org |
825
- | body? | Record<string, unknown> | Request body (only POST requests) |
826
- | headers? | OutgoingHttpHeaders | Avaliable HTTP headers |
827
- | queryParams? | Record<string,string> | url query params (to be appended to the already existing ones) |
828
- | resultPath? | string | response dot notation path to the value needed from the response |
829
- | fallbackValue? | unknown | default value to return if the API returns error |
830
- | preConditions? | TSchemaValidation | validations to occur before the request is made (check validations section) |
831
- | blockRequestWhenInvalid? | boolean | flag to only request the api config if the field is valid |
832
- | transform? | { callback:(payload) => unknown } | custom function to be passed as callback to transform the request in any other format |
859
+ | Prop | Type | Description |
860
+ | --------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | ------------------------------------------------------------------------------------- |
861
+ | [method](../../docs/form-engine-core/src/types/schema/type-aliases/TApiConfig.md#method) | 'GET' or 'POST' | HTTP method (only GET or POST) |
862
+ | [url](../../docs/form-engine-core/src/types/schema/type-aliases/TApiConfig.md#url) | string | Request url ex: http://mockapi.org |
863
+ | [body](../../docs/form-engine-core/src/types/schema/type-aliases/TApiConfig.md#body)? | Record<string, unknown> | Request body (only POST requests) |
864
+ | [headers](../../docs/form-engine-core/src/types/schema/type-aliases/TApiConfig.md#headers)? | OutgoingHttpHeaders | Avaliable HTTP headers |
865
+ | [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) |
866
+ | [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 |
867
+ | [fallbackValue](../../docs/form-engine-core/src/types/schema/type-aliases/TApiConfig.md#fallbackvalue)? | unknown | default value to return if the API returns error |
868
+ | [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) |
869
+ | [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 |
870
+ | [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 |
833
871
 
834
872
  ### From v2 to v3
835
873
 
@@ -869,7 +907,7 @@ const api = {
869
907
  };
870
908
  ```
871
909
 
872
- the API result is commonly used with `templating`, check [templating](#markdown-templating) section
910
+ the API result is commonly used with `templating`, check [templating](#templating) section
873
911
 
874
912
  <a id="resetvalues"></a>
875
913
 
@@ -877,14 +915,14 @@ the API result is commonly used with `templating`, check [templating](#markdown-
877
915
 
878
916
  resetValues lets you change input values with the same rules as validations
879
917
 
880
- | Prop | Type | Description |
881
- | -------------- | -------------------- | ---------------------------------------------------------------------------------- |
882
- | validations | TSchemaValidation | validations rules to be validated to reset the value to the configuration provided |
883
- | fields | string[] or string | field or fields that will recieve the resettled value |
884
- | events | Partial<TEvents>[] | events that will trigger the validation |
885
- | resettledValue | unknown[] or unknown | value or values to be set on the specified fields |
918
+ | Prop | Type | Description |
919
+ | --------------------------------------------------------------------------------------------- | -------------------- | ---------------------------------------------------------------------------------- |
920
+ | [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 |
921
+ | fields | string[] or string | field or fields that will recieve the resettled value |
922
+ | events | Partial<TEvents>[] | events that will trigger the validation |
923
+ | resettledValue | unknown[] or unknown | value or values to be set on the specified fields |
886
924
 
887
- 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
925
+ 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.
888
926
 
889
927
  ### from v2 to v3
890
928
 
@@ -1002,16 +1040,16 @@ resetPropertyValues: [
1002
1040
  bool: false,
1003
1041
  },
1004
1042
  },
1005
- ],
1043
+ ];
1006
1044
  ```
1007
1045
 
1008
- <a id="visibility">
1046
+ <a id="visibility"></a>
1009
1047
 
1010
1048
  ## **visibility**
1011
1049
 
1012
1050
  visibility prop is used to initiate the component with an initial visibility flag, before visibilityConditions take place, used on SSR
1013
1051
 
1014
- <a id="persistValue">
1052
+ <a id="persistValue"></a>
1015
1053
 
1016
1054
  ## **persistValue**
1017
1055
 
@@ -1104,9 +1142,12 @@ The avalialbe callback methods are:
1104
1142
  | onFocus | TFieldEvent | same as above |
1105
1143
  | onKeyDown | TFieldEvent | same as above |
1106
1144
  | onKeyUp | TFieldEvent | same as above |
1107
- | onMount | TFieldEvent | same as above |
1108
- | onApiResponse | TFieldEvent | same as above |
1109
1145
  | onClick | TFieldEvent | same as above |
1146
+ | onApiResponse | TFieldEvent | event occuring when a api response is ready |
1147
+ | onApiRequest | TFieldEvent | event occuring when a api resquest is started |
1148
+ | onMount | TFieldEvent | event occuring when a field is mounted or set visible |
1149
+ | onUnmount | TFieldEvent | event occuring when a field is unmounted or hidden |
1150
+ | onCleared | TFieldEvent | event occuring when the field value is set with resetValues |
1110
1151
  | onFormMount | TFormValues<T> | event occuring on form mount |
1111
1152
  | onData | TFormData<T> | event occuring when a value is changing via input or logic |
1112
1153
  | onSubmit | TFormValues<T> | event occuring when pressing the submit button defined on the form |
@@ -1123,7 +1164,7 @@ useFormGroup({ ids: ['form1', 'form2'], onData: (payload) => console.log(payload
1123
1164
  As `useForm`, `useFormGroup` serves the same purpose, but the difference is that it handles multiple forms and has limited callback functions to set:
1124
1165
 
1125
1166
  | method | payload | description |
1126
- |----------|-----------------------------------|-------------------------------------------------------------|
1167
+ | -------- | --------------------------------- | ----------------------------------------------------------- |
1127
1168
  | onData | TFormGroupOnDataEventPayload<T> | event occurring when a value is changing via input or logic |
1128
1169
  | onValid | TFormGroupOnValidEventPayload | event occurring when validation status changes on the form |
1129
1170
  | onSubmit | TFormGroupOnSubmitEventPayload<T> | event occurring when form submission is trigger |
@@ -1181,8 +1222,216 @@ Ex:
1181
1222
 
1182
1223
  Other than schema component properties like `validations`, `api`, etc.., it has additional properties to define the component, the associated form id and the name
1183
1224
 
1184
- | method | type | description |
1185
- | --------- | ---------- | --------------------------------------------------- |
1186
- | mapper | TMapper<T> | mapper configuration to define the component |
1187
- | name | string | field name to be identified on the form |
1188
- | formIndex | string | index of the form to be identified on the formGroup |
1225
+ | method | type | description |
1226
+ | --------- | ---------- | ------------------------------------------------------------------------------------------------------------------------ |
1227
+ | mapper | TMapper<T> | mapper configuration to define the component |
1228
+ | name | string | field name to be identified on the form |
1229
+ | formIndex | string | index of the form to be identified on the formGroup |
1230
+ | component | string | if mappers is provided from the formgroup context, you can assign the mapper by it's name instead of whole mapper config |
1231
+
1232
+ <a id="asformfieldrepeater"></a>
1233
+
1234
+ ## **AsFormFieldRepeater**
1235
+
1236
+ Component adapter to aid managing multiple forms that shares the same inputs
1237
+
1238
+ Props:
1239
+
1240
+ | Attr | Type | Description |
1241
+ | ----------------- | --------------------------------------------------------- | -------------------------------------------------------------------------- |
1242
+ | RepeaterComponent | ElementType<{ formIndex: string }> | Component with form schema or AsFormFieldBuilder elements |
1243
+ | addFieldName | string | name of the button in the RepeaterComponent to add forms |
1244
+ | removeFieldName | string | name of the button in the RepeaterComponent to remove forms |
1245
+ | existingElements | Record<string, unknown>[] | existing values emmitted from stateUpdater to restore previous used values |
1246
+ | initialElements | number | elements to be pre-rendered when the form is presented |
1247
+ | stateUpdater | (payload: TFormGroupOnDataEventPayload<unknown>) => void; | callback function that reacts to RepeaterComponet values changes |
1248
+ | formPrefix | string | prefix for form names ex, prefix: foo, forms: ["foo1","foo2","foo3"] |
1249
+ | RepeaterFooter | ElementType<{ formIndex: string }> | Component with a button to add forms on the last position |
1250
+
1251
+ Common use case for this Adapter is to manage multiple forms that collects the same data ex: multiple person personal data
1252
+
1253
+ # Example
1254
+
1255
+ ## RepeaterComponent
1256
+
1257
+ ```javascript
1258
+ const FormElement = ({ formIndex }: { formIndex: string }) => {
1259
+ return (
1260
+ <>
1261
+ <AsFormFieldBuilder formIndex={formIndex} name="foo" component="input" props={{ label: 'foo' }} />
1262
+ <AsFormFieldBuilder formIndex={formIndex} name="bar" component="input" props={{ label: 'bar' }} />
1263
+ <AsFormFieldBuilder
1264
+ formIndex={formIndex}
1265
+ name="addForm"
1266
+ component="button"
1267
+ props={{
1268
+ text: 'add element',
1269
+ }}
1270
+ />
1271
+ <AsFormFieldBuilder
1272
+ formIndex={formIndex}
1273
+ name="removeForm"
1274
+ component="button"
1275
+ props={{
1276
+ text: 'remove element',
1277
+ }}
1278
+ />
1279
+ </>
1280
+ );
1281
+ };
1282
+ ```
1283
+
1284
+ Important notes when developing this component is that it needs to receive an object with a key **formIndex**
1285
+
1286
+ Optionally, but to add form management functionality, add two buttons with **ON_FIELD_CLICK** event capture (can't be of type submit)
1287
+ both that Field button names will be needed on the next step
1288
+
1289
+ ## RepeaterFooter
1290
+
1291
+ Optionally, you can develop a footer component with a button that will be added the bottom of the repeated forms
1292
+ and when you press that button will add a form at the bottom of the list
1293
+
1294
+ 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)
1295
+ Note: the button name needs to be different from the names you gave to the buttons you are passing on the RepeaterComponent
1296
+
1297
+ ```javascript
1298
+ const FormElementFooter = ({ formIndex }: { formIndex: string }) => {
1299
+ return (
1300
+ <AsFormFieldBuilder
1301
+ formIndex={formIndex}
1302
+ name="addFormBelow"
1303
+ component="button"
1304
+ props={{
1305
+ text: 'add element below',
1306
+ }}
1307
+ />
1308
+ );
1309
+ };
1310
+ ```
1311
+
1312
+ ## AsFormFieldRepeater
1313
+
1314
+ Set the AsFormFieldRepeater adapter with the element you created above and the names that you gave to the button fields
1315
+
1316
+ ```javascript
1317
+ <AsFormFieldRepeater
1318
+ RepeaterComponent={FormElement}
1319
+ RepeaterFooter={FormElementFooter}
1320
+ addFieldName="addForm"
1321
+ removeFieldName="removeForm"
1322
+ formPrefix="insured"
1323
+ stateUpdater={(payload) => {
1324
+ console.log(payload);
1325
+ }}
1326
+ />
1327
+ ```
1328
+
1329
+ **RepeaterComponent** and **RepeaterFooter** you set the elements created above
1330
+
1331
+ **addFieldName** you set the name to the button that will add a form on the position it's being clicked
1332
+
1333
+ **removeFieldName** you set the name to the button that will remove a form on the position it's being clicked
1334
+
1335
+ **formPrefix** the prefix for the forms emmited on **stateUpdater** enumerated
1336
+
1337
+ **stateUpdater** callback function that will receive the form values (similar to onData)
1338
+
1339
+
1340
+ <a id="ssr"></a>
1341
+
1342
+ ## **Server-Side Rendering (SSR)**
1343
+
1344
+ Form Engine supports SSR with React frameworks like Next.js (App Router and Pages Router) and Remix. The form produces meaningful HTML on the server, reducing time-to-first-paint and improving SEO.
1345
+
1346
+ ### How it works
1347
+
1348
+ 1. **Server render**: The `<Form />` component creates the `FormCore` instance synchronously during render via `useMemo`. Static props (non-template) are rendered directly. Template expressions (`${...}`) are stripped by `filterProps` to avoid raw expressions in the HTML.
1349
+
1350
+ 2. **Client hydration**: After hydration, `useEffect` hooks activate field mounting, RxJS subscriptions, and the template system (`subscribedTemplates` + `refreshTemplates`). Template props resolve at this point with their dynamic values.
1351
+
1352
+ ### What renders during SSR
1353
+
1354
+ | Content | SSR behavior |
1355
+ |---------|-------------|
1356
+ | Form structure (`<form>`, fields) | ✅ Rendered with correct components |
1357
+ | Static props (`label`, `placeholder`, etc.) | ✅ Rendered normally |
1358
+ | Template props (`${iVars.*}`, `${fields.*}`) | Stripped during SSR, resolved after hydration |
1359
+ | `visibility: false` fields | ✅ Correctly hidden |
1360
+ | Field interactivity (onChange, validation) | Activates after hydration |
1361
+ | API calls (`ON_FIELD_MOUNT`) | Execute after hydration |
1362
+
1363
+ ### `prefetchedData` prop
1364
+
1365
+ For fields that depend on API responses (e.g., dropdowns loaded from a backend), you can pre-fetch data on the server and pass it to the form. This populates the field's internal API response cache so that `refreshTemplates` can resolve API-based templates immediately after hydration — without making a new request.
1366
+
1367
+ ```typescript
1368
+ import { Form, FormGroupContextProvider } from '@bolttech/form-engine';
1369
+
1370
+ // Server-side: fetch data before render
1371
+ const countries = await fetch('https://api.example.com/countries').then(r => r.json());
1372
+
1373
+ // Pass to form
1374
+ <FormGroupContextProvider mappers={mappers}>
1375
+ <Form
1376
+ schema={schema}
1377
+ iVars={{ title: 'Insurance Form' }}
1378
+ initialValues={{ name: 'John' }}
1379
+ prefetchedData={{
1380
+ countryField: {
1381
+ defaultResponse: countries,
1382
+ },
1383
+ stateField: {
1384
+ namedResponses: {
1385
+ byCountry: [{ id: 'SP', label: 'São Paulo' }],
1386
+ },
1387
+ },
1388
+ }}
1389
+ />
1390
+ </FormGroupContextProvider>
1391
+ ```
1392
+
1393
+ ### `TPrefetchedFieldData` interface
1394
+
1395
+ ```typescript
1396
+ interface TPrefetchedFieldData {
1397
+ /** Pre-fetched response for the field's default API config */
1398
+ defaultResponse?: unknown;
1399
+ /** Pre-fetched responses keyed by named API config name */
1400
+ namedResponses?: Record<string, unknown>;
1401
+ }
1402
+ ```
1403
+
1404
+ ### Next.js App Router
1405
+
1406
+ The package includes `'use client'` directive in the built output. Use it inside a client component:
1407
+
1408
+ ```typescript
1409
+ // app/form/page.tsx (Server Component)
1410
+ import { FormClient } from './FormClient';
1411
+
1412
+ export default async function Page() {
1413
+ const countries = await fetch('https://api.example.com/countries').then(r => r.json());
1414
+ return <FormClient countries={countries} />;
1415
+ }
1416
+
1417
+ // app/form/FormClient.tsx (Client Component)
1418
+ 'use client';
1419
+ import { Form, FormGroupContextProvider } from '@bolttech/form-engine';
1420
+
1421
+ export function FormClient({ countries }) {
1422
+ return (
1423
+ <FormGroupContextProvider mappers={mappers}>
1424
+ <Form
1425
+ schema={schema}
1426
+ prefetchedData={{ country: { defaultResponse: countries } }}
1427
+ />
1428
+ </FormGroupContextProvider>
1429
+ );
1430
+ }
1431
+ ```
1432
+
1433
+ ### Minimum requirements
1434
+
1435
+ - Node.js 18+ (for native `fetch` support in the core)
1436
+ - React 18+ (for SSR/Streaming support)
1437
+ - `@bolttech/form-engine-core` >= 1.1.0