commons-shared-web-ui 0.0.50 → 0.0.52

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.
Files changed (187) hide show
  1. package/fesm2022/commons-shared-web-ui.mjs +14557 -0
  2. package/fesm2022/commons-shared-web-ui.mjs.map +1 -0
  3. package/index.d.ts +4534 -0
  4. package/package.json +34 -53
  5. package/src/lib/styles/utilities.scss +1 -0
  6. package/.claude/settings.local.json +0 -10
  7. package/documentation/alert.md +0 -123
  8. package/documentation/button-dropdown.md +0 -126
  9. package/documentation/button.md +0 -184
  10. package/documentation/cards-usage-guidelines.md +0 -131
  11. package/documentation/configurable-form.md +0 -605
  12. package/documentation/confirmation-modal.md +0 -250
  13. package/documentation/filter-sidebar.md +0 -178
  14. package/documentation/filter-table-selector.md +0 -228
  15. package/documentation/form-builder.md +0 -597
  16. package/documentation/form-components.md +0 -384
  17. package/documentation/nav.md +0 -427
  18. package/documentation/pagination.md +0 -181
  19. package/documentation/side-nav-documentation.md +0 -169
  20. package/documentation/smart-form.md +0 -2405
  21. package/documentation/smart-table.md +0 -1221
  22. package/documentation/snackbar.md +0 -118
  23. package/documentation/style-externalization.md +0 -88
  24. package/documentation/summary-card.md +0 -279
  25. package/ng-package.json +0 -28
  26. package/src/lib/modules/alert/alert.models.ts +0 -6
  27. package/src/lib/modules/alert/alert.module.ts +0 -16
  28. package/src/lib/modules/alert/components/alert/alert.component.html +0 -27
  29. package/src/lib/modules/alert/components/alert/alert.component.scss +0 -92
  30. package/src/lib/modules/alert/components/alert/alert.component.ts +0 -81
  31. package/src/lib/modules/button/button.models.ts +0 -13
  32. package/src/lib/modules/button/button.module.ts +0 -16
  33. package/src/lib/modules/button/components/button/button.component.html +0 -22
  34. package/src/lib/modules/button/components/button/button.component.scss +0 -88
  35. package/src/lib/modules/button/components/button/button.component.ts +0 -67
  36. package/src/lib/modules/button-dropdown/button-dropdown.models.ts +0 -26
  37. package/src/lib/modules/button-dropdown/button-dropdown.module.ts +0 -22
  38. package/src/lib/modules/button-dropdown/button-dropdown.theme.scss +0 -87
  39. package/src/lib/modules/button-dropdown/components/button-dropdown/button-dropdown.component.html +0 -41
  40. package/src/lib/modules/button-dropdown/components/button-dropdown/button-dropdown.component.scss +0 -135
  41. package/src/lib/modules/button-dropdown/components/button-dropdown/button-dropdown.component.ts +0 -160
  42. package/src/lib/modules/configurable-form/component/configurable-form.component.html +0 -294
  43. package/src/lib/modules/configurable-form/component/configurable-form.component.scss +0 -503
  44. package/src/lib/modules/configurable-form/component/configurable-form.component.ts +0 -628
  45. package/src/lib/modules/configurable-form/configurable-form.examples.ts +0 -154
  46. package/src/lib/modules/configurable-form/configurable-form.model.ts +0 -131
  47. package/src/lib/modules/configurable-form/configurable-form.module.ts +0 -19
  48. package/src/lib/modules/confirmation-modal/components/confirmation-modal/confirmation-modal.component.html +0 -77
  49. package/src/lib/modules/confirmation-modal/components/confirmation-modal/confirmation-modal.component.scss +0 -395
  50. package/src/lib/modules/confirmation-modal/components/confirmation-modal/confirmation-modal.component.ts +0 -266
  51. package/src/lib/modules/confirmation-modal/confirmation-modal.models.ts +0 -71
  52. package/src/lib/modules/confirmation-modal/confirmation-modal.module.ts +0 -20
  53. package/src/lib/modules/filter/components/filter/filter.component.html +0 -131
  54. package/src/lib/modules/filter/components/filter/filter.component.scss +0 -245
  55. package/src/lib/modules/filter/components/filter/filter.component.ts +0 -216
  56. package/src/lib/modules/filter/filter.models.ts +0 -88
  57. package/src/lib/modules/filter/filter.module.ts +0 -24
  58. package/src/lib/modules/filter-sidebar/components/filter-sidebar/filter-sidebar.component.html +0 -112
  59. package/src/lib/modules/filter-sidebar/components/filter-sidebar/filter-sidebar.component.scss +0 -186
  60. package/src/lib/modules/filter-sidebar/components/filter-sidebar/filter-sidebar.component.ts +0 -163
  61. package/src/lib/modules/filter-sidebar/filter-sidebar.models.ts +0 -95
  62. package/src/lib/modules/filter-sidebar/filter-sidebar.module.ts +0 -24
  63. package/src/lib/modules/filter-table-selector/components/filter-table-selector/filter-table-selector.component.html +0 -73
  64. package/src/lib/modules/filter-table-selector/components/filter-table-selector/filter-table-selector.component.scss +0 -321
  65. package/src/lib/modules/filter-table-selector/components/filter-table-selector/filter-table-selector.component.ts +0 -361
  66. package/src/lib/modules/filter-table-selector/filter-table-selector.models.ts +0 -91
  67. package/src/lib/modules/filter-table-selector/filter-table-selector.module.ts +0 -22
  68. package/src/lib/modules/form-builder/components/field-configurator/configurator-config-panel/configurator-config-panel.component.html +0 -63
  69. package/src/lib/modules/form-builder/components/field-configurator/configurator-config-panel/configurator-config-panel.component.scss +0 -496
  70. package/src/lib/modules/form-builder/components/field-configurator/configurator-config-panel/configurator-config-panel.component.ts +0 -445
  71. package/src/lib/modules/form-builder/components/field-configurator/configurator-tree/configurator-tree.component.html +0 -75
  72. package/src/lib/modules/form-builder/components/field-configurator/configurator-tree/configurator-tree.component.scss +0 -210
  73. package/src/lib/modules/form-builder/components/field-configurator/configurator-tree/configurator-tree.component.ts +0 -55
  74. package/src/lib/modules/form-builder/components/field-configurator/field-configurator.component.html +0 -25
  75. package/src/lib/modules/form-builder/components/field-configurator/field-configurator.component.scss +0 -82
  76. package/src/lib/modules/form-builder/components/field-configurator/field-configurator.component.ts +0 -95
  77. package/src/lib/modules/form-builder/components/field-selection/field-selection.component.html +0 -20
  78. package/src/lib/modules/form-builder/components/field-selection/field-selection.component.scss +0 -37
  79. package/src/lib/modules/form-builder/components/field-selection/field-selection.component.ts +0 -94
  80. package/src/lib/modules/form-builder/components/field-selection/group-node/group-node.component.html +0 -46
  81. package/src/lib/modules/form-builder/components/field-selection/group-node/group-node.component.scss +0 -102
  82. package/src/lib/modules/form-builder/components/field-selection/group-node/group-node.component.ts +0 -50
  83. package/src/lib/modules/form-builder/components/field-selection/selection-field-node/selection-field-node.component.html +0 -35
  84. package/src/lib/modules/form-builder/components/field-selection/selection-field-node/selection-field-node.component.scss +0 -67
  85. package/src/lib/modules/form-builder/components/field-selection/selection-field-node/selection-field-node.component.ts +0 -34
  86. package/src/lib/modules/form-builder/components/field-selection/selection-section-node/selection-section-node.component.html +0 -68
  87. package/src/lib/modules/form-builder/components/field-selection/selection-section-node/selection-section-node.component.scss +0 -113
  88. package/src/lib/modules/form-builder/components/field-selection/selection-section-node/selection-section-node.component.ts +0 -74
  89. package/src/lib/modules/form-builder/configs/field-type-schema.map.ts +0 -533
  90. package/src/lib/modules/form-builder/form-builder.module.ts +0 -36
  91. package/src/lib/modules/form-builder/index.ts +0 -9
  92. package/src/lib/modules/form-builder/models/builder.models.ts +0 -7
  93. package/src/lib/modules/form-builder/models/field-configurator.models.ts +0 -38
  94. package/src/lib/modules/form-builder/models/field-selection.models.ts +0 -51
  95. package/src/lib/modules/form-builder/services/field-configurator.service.ts +0 -258
  96. package/src/lib/modules/form-builder/services/field-selection.service.ts +0 -299
  97. package/src/lib/modules/form-builder/services/form-schema-tree.service.ts +0 -670
  98. package/src/lib/modules/form-builder/tokens/builder.tokens.ts +0 -10
  99. package/src/lib/modules/form-builder/utils/constants.ts +0 -43
  100. package/src/lib/modules/form-components/components/checkbox/checkbox.component.html +0 -29
  101. package/src/lib/modules/form-components/components/checkbox/checkbox.component.scss +0 -111
  102. package/src/lib/modules/form-components/components/checkbox/checkbox.component.ts +0 -207
  103. package/src/lib/modules/form-components/components/checkbox/checkbox.models.ts +0 -35
  104. package/src/lib/modules/form-components/components/datepicker/datepicker.component.html +0 -42
  105. package/src/lib/modules/form-components/components/datepicker/datepicker.component.scss +0 -115
  106. package/src/lib/modules/form-components/components/datepicker/datepicker.component.ts +0 -267
  107. package/src/lib/modules/form-components/components/datepicker/datepicker.models.ts +0 -45
  108. package/src/lib/modules/form-components/components/dropdown/dropdown.component.html +0 -74
  109. package/src/lib/modules/form-components/components/dropdown/dropdown.component.scss +0 -252
  110. package/src/lib/modules/form-components/components/dropdown/dropdown.component.ts +0 -377
  111. package/src/lib/modules/form-components/components/dropdown/dropdown.models.ts +0 -53
  112. package/src/lib/modules/form-components/components/input/input.component.html +0 -51
  113. package/src/lib/modules/form-components/components/input/input.component.scss +0 -128
  114. package/src/lib/modules/form-components/components/input/input.component.ts +0 -250
  115. package/src/lib/modules/form-components/components/input/input.models.ts +0 -55
  116. package/src/lib/modules/form-components/components/radio/radio.component.html +0 -22
  117. package/src/lib/modules/form-components/components/radio/radio.component.scss +0 -107
  118. package/src/lib/modules/form-components/components/radio/radio.component.ts +0 -181
  119. package/src/lib/modules/form-components/components/radio/radio.models.ts +0 -39
  120. package/src/lib/modules/form-components/components/search/search.component.html +0 -15
  121. package/src/lib/modules/form-components/components/search/search.component.scss +0 -87
  122. package/src/lib/modules/form-components/components/search/search.component.ts +0 -213
  123. package/src/lib/modules/form-components/components/search/search.models.ts +0 -40
  124. package/src/lib/modules/form-components/components/toggle/toggle.component.html +0 -15
  125. package/src/lib/modules/form-components/components/toggle/toggle.component.scss +0 -81
  126. package/src/lib/modules/form-components/components/toggle/toggle.component.ts +0 -166
  127. package/src/lib/modules/form-components/components/toggle/toggle.models.ts +0 -27
  128. package/src/lib/modules/form-components/directives/click-outside.directive.ts +0 -22
  129. package/src/lib/modules/form-components/form-components.module.ts +0 -41
  130. package/src/lib/modules/material/material.module.ts +0 -94
  131. package/src/lib/modules/nav/components/nav/nav.component.html +0 -34
  132. package/src/lib/modules/nav/components/nav/nav.component.scss +0 -171
  133. package/src/lib/modules/nav/components/nav/nav.component.ts +0 -82
  134. package/src/lib/modules/nav/nav.models.ts +0 -31
  135. package/src/lib/modules/nav/nav.module.ts +0 -17
  136. package/src/lib/modules/pagination/components/pagination/pagination.component.html +0 -52
  137. package/src/lib/modules/pagination/components/pagination/pagination.component.scss +0 -155
  138. package/src/lib/modules/pagination/components/pagination/pagination.component.ts +0 -109
  139. package/src/lib/modules/pagination/pagination.module.ts +0 -17
  140. package/src/lib/modules/side-nav/components/side-nav/side-nav.component.html +0 -56
  141. package/src/lib/modules/side-nav/components/side-nav/side-nav.component.scss +0 -342
  142. package/src/lib/modules/side-nav/components/side-nav/side-nav.component.ts +0 -135
  143. package/src/lib/modules/side-nav/side-nav.models.ts +0 -38
  144. package/src/lib/modules/side-nav/side-nav.module.ts +0 -16
  145. package/src/lib/modules/smart-form/components/form-field/form-field.component.html +0 -1196
  146. package/src/lib/modules/smart-form/components/form-field/form-field.component.scss +0 -2014
  147. package/src/lib/modules/smart-form/components/form-field/form-field.component.ts +0 -2525
  148. package/src/lib/modules/smart-form/components/form-section/form-section.component.html +0 -65
  149. package/src/lib/modules/smart-form/components/form-section/form-section.component.scss +0 -209
  150. package/src/lib/modules/smart-form/components/form-section/form-section.component.ts +0 -131
  151. package/src/lib/modules/smart-form/components/smart-form/smart-form.component.html +0 -253
  152. package/src/lib/modules/smart-form/components/smart-form/smart-form.component.scss +0 -689
  153. package/src/lib/modules/smart-form/components/smart-form/smart-form.component.ts +0 -1124
  154. package/src/lib/modules/smart-form/index.ts +0 -10
  155. package/src/lib/modules/smart-form/models/form-schema.model.ts +0 -733
  156. package/src/lib/modules/smart-form/models/hierarchy-config.model.ts +0 -21
  157. package/src/lib/modules/smart-form/services/expression.service.ts +0 -75
  158. package/src/lib/modules/smart-form/services/smart-form-controller.service.ts +0 -65
  159. package/src/lib/modules/smart-form/smart-form.examples.ts +0 -1324
  160. package/src/lib/modules/smart-form/smart-form.module.ts +0 -36
  161. package/src/lib/modules/smart-form/utils/translation.utils.ts +0 -82
  162. package/src/lib/modules/smart-form/utils/trusted-url.pipe.ts +0 -25
  163. package/src/lib/modules/smart-form/utils/validation.utils.ts +0 -98
  164. package/src/lib/modules/smart-table/components/smart-table/smart-table.component.html +0 -283
  165. package/src/lib/modules/smart-table/components/smart-table/smart-table.component.scss +0 -685
  166. package/src/lib/modules/smart-table/components/smart-table/smart-table.component.ts +0 -1128
  167. package/src/lib/modules/smart-table/models/table-config.model.ts +0 -207
  168. package/src/lib/modules/smart-table/smart-table.module.ts +0 -30
  169. package/src/lib/modules/smart-table/utils/safe-html.pipe.ts +0 -28
  170. package/src/lib/modules/smart-table/utils/smart-table.utils.ts +0 -18
  171. package/src/lib/modules/snackbar/components/snackbar.component.html +0 -41
  172. package/src/lib/modules/snackbar/components/snackbar.component.scss +0 -99
  173. package/src/lib/modules/snackbar/components/snackbar.component.ts +0 -18
  174. package/src/lib/modules/snackbar/models/snackbar.models.ts +0 -10
  175. package/src/lib/modules/snackbar/services/snackbar.service.ts +0 -40
  176. package/src/lib/modules/snackbar/snackbar.module.ts +0 -11
  177. package/src/lib/modules/summary-card/components/summary-card/summary-card.component.html +0 -47
  178. package/src/lib/modules/summary-card/components/summary-card/summary-card.component.scss +0 -199
  179. package/src/lib/modules/summary-card/components/summary-card/summary-card.component.ts +0 -126
  180. package/src/lib/modules/summary-card/summary-card.module.ts +0 -18
  181. package/src/lib/shared-ui.module.ts +0 -44
  182. package/src/lib/utils/constants.ts +0 -11
  183. package/src/lib/utils/storage.utils.ts +0 -37
  184. package/src/lib/utils/string.utils.ts +0 -23
  185. package/src/lib/utils/translation.utils.ts +0 -87
  186. package/src/public-api.ts +0 -104
  187. package/tsconfig.lib.json +0 -15
@@ -1,2405 +0,0 @@
1
- # Smart Form Module
2
-
3
- A powerful, JSON-driven dynamic form builder for Angular applications. This module allows you to create complex forms with conditional visibility, auto-calculated fields, multi-section support, stepper navigation, repeatable groups, column-based layouts, automatic API submission, and full i18n support — using simple JSON configurations.
4
-
5
- ## Table of Contents
6
-
7
- - [Installation](#installation)
8
- - [Quick Start](#quick-start)
9
- - [Form Types](#form-types)
10
- - [Field Types](#field-types)
11
- - [Layout System](#layout-system)
12
- - [Configuration Options](#configuration-options)
13
- - [Advanced Features](#advanced-features)
14
- - [i18n / Translation Support](#i18n--translation-support)
15
- - [API Submission](#api-submission)
16
- - [API Authentication (Token)](#api-authentication-token)
17
- - [Theme Configuration](#theme-configuration)
18
- - [Examples](#examples)
19
- - [API Reference](#api-reference)
20
- - [Best Practices](#best-practices)
21
- - [Troubleshooting](#troubleshooting)
22
-
23
- ---
24
-
25
- ## Installation
26
-
27
- To install the latest version of the `commons-shared-web-ui` library, run the following command:
28
-
29
- ```bash
30
- npm install commons-shared-web-ui@latest
31
- ```
32
-
33
- 1. Import the module in your Angular application:
34
-
35
- ```typescript
36
- import { SmartFormModule } from "./modules/smart-form/smart-form.module";
37
-
38
- @NgModule({
39
- imports: [SmartFormModule],
40
- })
41
- export class AppModule {}
42
- ```
43
-
44
- ---
45
-
46
- ## Quick Start
47
-
48
- ### Basic Usage
49
-
50
- ```typescript
51
- import { Component } from "@angular/core";
52
-
53
- @Component({
54
- selector: "app-example",
55
- template: `
56
- <lib-smart-form
57
- [formJson]="formJson"
58
- [initialValues]="initialValues"
59
- [labels]="labels"
60
- (submit)="onSubmit($event)"
61
- >
62
- </lib-smart-form>
63
- `,
64
- })
65
- export class ExampleComponent {
66
- formJson = JSON.stringify({
67
- entityType: "USER",
68
- label: "FORM.TITLE",
69
- formType: "SECTION",
70
- sectionConfig: {
71
- children: [
72
- {
73
- name: "firstName",
74
- label: "FIELD.FIRST_NAME",
75
- type: "TEXT_INPUT",
76
- subType: "SHORT",
77
- required: true,
78
- },
79
- {
80
- name: "email",
81
- label: "FIELD.EMAIL",
82
- type: "TEXT_INPUT",
83
- subType: "EMAIL",
84
- required: true,
85
- },
86
- ],
87
- },
88
- });
89
-
90
- initialValues = { firstName: "John" };
91
-
92
- labels = {
93
- "FORM.TITLE": "User Registration",
94
- "FIELD.FIRST_NAME": "First Name",
95
- "FIELD.EMAIL": "Email Address",
96
- };
97
-
98
- onSubmit(data: any) {
99
- console.log("Form submitted:", data);
100
- }
101
- }
102
- ```
103
-
104
- ---
105
-
106
- ## Form Types
107
-
108
- ### 1. Section Form (SECTION)
109
-
110
- A simple form with all fields displayed at once.
111
-
112
- ```json
113
- {
114
- "entityType": "USER",
115
- "label": "User Form",
116
- "formType": "SECTION",
117
- "sectionConfig": {
118
- "children": [...]
119
- }
120
- }
121
- ```
122
-
123
- ### 2. Stepper Form (STEPPER)
124
-
125
- A multi-step form with navigation between steps. Each step is a `GROUP` field with a `sectionConfig`.
126
-
127
- ```json
128
- {
129
- "entityType": "USER",
130
- "label": "User Registration",
131
- "formType": "STEPPER",
132
- "stepperConfig": {
133
- "children": [
134
- {
135
- "type": "GROUP",
136
- "subType": "SECTION",
137
- "sectionConfig": {
138
- "label": "Step 1: Basic Info",
139
- "children": [...]
140
- }
141
- },
142
- {
143
- "type": "GROUP",
144
- "subType": "SECTION",
145
- "sectionConfig": {
146
- "label": "Step 2: Contact Info",
147
- "children": [...]
148
- }
149
- }
150
- ],
151
- "showStep": true,
152
- "isHorizontal": true
153
- }
154
- }
155
- ```
156
-
157
- ### 3. Section Stepper (SECTION + `sectionStepper`)
158
-
159
- A `SECTION` form where top-level `GROUP` children are rendered as a horizontal step-progress bar at the top, showing one section at a time. Set `"sectionStepper": true` to enable it explicitly. The form auto-detects it when all top-level children are `GROUP` type and there are more than one — set `"sectionStepper": false` to suppress auto-detection.
160
-
161
- The component automatically renders **Previous** and **Next** buttons in the action bar. Any configured `actionBarConfig` buttons appear alongside these navigation buttons.
162
-
163
- ```json
164
- {
165
- "entityType": "REGISTRATION",
166
- "label": "Multi-Step Registration",
167
- "formType": "SECTION",
168
- "sectionStepper": true,
169
- "sectionConfig": {
170
- "children": [
171
- {
172
- "type": "GROUP",
173
- "subType": "SECTION",
174
- "sectionConfig": {
175
- "label": "Personal Info",
176
- "children": [...]
177
- }
178
- },
179
- {
180
- "type": "GROUP",
181
- "subType": "SECTION",
182
- "sectionConfig": {
183
- "label": "Contact Details",
184
- "children": [...]
185
- }
186
- },
187
- {
188
- "type": "GROUP",
189
- "subType": "SECTION",
190
- "sectionConfig": {
191
- "label": "Review & Submit",
192
- "children": [...]
193
- }
194
- }
195
- ]
196
- }
197
- }
198
- ```
199
-
200
- | Setting | Behaviour |
201
- |---------|-----------|
202
- | `"sectionStepper": true` | Always enables section stepper |
203
- | `"sectionStepper": false` | Disables section stepper; renders all sections at once in the regular layout |
204
- | Omitted | Auto-detected when all top-level children are `GROUP` type and there are more than one |
205
-
206
- ---
207
-
208
- ## Field Types
209
-
210
- ### 1. Text Input (TEXT_INPUT)
211
-
212
- **SubTypes:** `SHORT`, `LONG`, `EMAIL`, `PHONE`, `PASSWORD`
213
-
214
- ```json
215
- {
216
- "name": "firstName",
217
- "label": "First Name",
218
- "type": "TEXT_INPUT",
219
- "subType": "SHORT",
220
- "required": true,
221
- "hint": "Enter your first name",
222
- "placeholder": "e.g. John",
223
- "textConfig": {
224
- "length": { "min": 2, "max": 50 },
225
- "pattern": "^[A-Za-z ]+$",
226
- "patternMessage": "Only alphabets and spaces are allowed"
227
- }
228
- }
229
- ```
230
-
231
- **Password with match validation** (`subType: PASSWORD` + `matchField`):
232
-
233
- ```json
234
- {
235
- "name": "password",
236
- "label": "Password",
237
- "type": "TEXT_INPUT",
238
- "subType": "PASSWORD",
239
- "required": true,
240
- "textConfig": { "length": { "min": 8, "max": 64 } }
241
- },
242
- {
243
- "name": "confirmPassword",
244
- "label": "Confirm Password",
245
- "type": "TEXT_INPUT",
246
- "subType": "PASSWORD",
247
- "required": true,
248
- "textConfig": { "matchField": "password" }
249
- }
250
- ```
251
-
252
- The `matchField` property tells the field to validate that its value equals the named sibling field. If the values differ, a `passwordMismatch` error is added and a user-friendly message is displayed.
253
-
254
- ### 2. Number Input (NUMBER_INPUT)
255
-
256
- **SubTypes:** `INTEGER`, `DECIMAL`
257
-
258
- ```json
259
- {
260
- "name": "age",
261
- "label": "Age",
262
- "type": "NUMBER_INPUT",
263
- "subType": "INTEGER",
264
- "required": true,
265
- "numberConfig": { "min": 18, "max": 100, "step": 1 }
266
- }
267
- ```
268
-
269
- ### 3. Date Input (DATE)
270
-
271
- **SubTypes:** `SINGLE`
272
-
273
- ```json
274
- {
275
- "name": "birthDate",
276
- "label": "Date of Birth",
277
- "type": "DATE",
278
- "subType": "SINGLE",
279
- "required": true,
280
- "dateConfig": {
281
- "allowFuture": false,
282
- "minDate": "1920-01-01",
283
- "maxDate": "2010-12-31"
284
- }
285
- }
286
- ```
287
-
288
- **`dateConfig` properties**
289
-
290
- | Property | Type | Description |
291
- |---|---|---|
292
- | `allowFuture` | `boolean` | When `false`, dates after today are blocked (default: `true`) |
293
- | `minDate` | `string` | Static minimum date in `YYYY-MM-DD` format |
294
- | `maxDate` | `string` | Static maximum date in `YYYY-MM-DD` format |
295
- | `minDateField` | `string` | Name of a sibling field whose current value is used as the dynamic minimum date. When the source field changes, the min date updates reactively. If the current field's value is now before the new minimum, it is automatically cleared. |
296
- | `inputReadonly` | `boolean` | When `true`, the text input is read-only — the user can only pick a date from the calendar, not type one. Default: `false` |
297
-
298
- **Dynamic min date (linked to another field)**
299
-
300
- Use `minDateField` to link the minimum of an end-date picker to a start-date field:
301
-
302
- ```json
303
- [
304
- {
305
- "name": "startDate",
306
- "label": "Start Date",
307
- "type": "DATE",
308
- "subType": "SINGLE",
309
- "required": true,
310
- "dateConfig": { "inputReadonly": true }
311
- },
312
- {
313
- "name": "endDate",
314
- "label": "End Date",
315
- "type": "DATE",
316
- "subType": "SINGLE",
317
- "required": true,
318
- "dateConfig": {
319
- "inputReadonly": true,
320
- "minDateField": "startDate"
321
- }
322
- }
323
- ]
324
- ```
325
-
326
- The End Date picker automatically sets its minimum to whatever value `startDate` holds. If the user later picks an earlier start date, `endDate` is cleared automatically.
327
-
328
- ### 4. Time Input (TIME)
329
-
330
- **SubTypes:** `SINGLE`
331
-
332
- ```json
333
- {
334
- "name": "meetingTime",
335
- "label": "Meeting Time",
336
- "type": "TIME",
337
- "subType": "SINGLE",
338
- "required": true,
339
- "placeholder": "Select Time"
340
- }
341
- ```
342
-
343
- **`timeConfig` options** (all optional):
344
-
345
- | Key | Type | Description |
346
- | --- | --- | --- |
347
- | `minTime` | string | Explicit minimum time in 24-hour `"HH:mm"` format (e.g. `"09:00"`). |
348
- | `maxTime` | string | Explicit maximum time in 24-hour `"HH:mm"` format (e.g. `"18:00"`). |
349
- | `inputReadonly` | boolean | When true, the input is readonly. |
350
- | `minTimeField` | string | Name of a sibling TIME field whose value is used as the dynamic minimum. When it changes, this field's minimum updates and any now-invalid value (earlier than the new minimum) is cleared. Mirrors `dateConfig.minTimeField`. |
351
-
352
- **Start / End time pair** — the end time cannot be earlier than the start time (same pattern as `dateConfig.minDateField`):
353
-
354
- ```json
355
- {
356
- "name": "startTime",
357
- "label": "Start Time",
358
- "type": "TIME",
359
- "required": true,
360
- "colSpan": 2
361
- },
362
- {
363
- "name": "endTime",
364
- "label": "End Time",
365
- "type": "TIME",
366
- "required": true,
367
- "colSpan": 2,
368
- "timeConfig": {
369
- "minTimeField": "startTime"
370
- }
371
- }
372
- ```
373
-
374
- ### 5. Autocomplete (AUTOCOMPLETE)
375
-
376
- A searchable input backed by Angular Material's `mat-autocomplete`. As the user types, the option list is filtered by label or code. The form control stores the **code** value, while the input shows the human-readable **label**.
377
-
378
- Autocomplete fields now use a dedicated `autocompleteConfig` for specialized behavior, while still using `optionConfig` for core API/data settings.
379
-
380
- #### Basic Usage (Local Filtering)
381
-
382
- ```json
383
- {
384
- "name": "country",
385
- "label": "Country",
386
- "type": "AUTOCOMPLETE",
387
- "subType": "SINGLE",
388
- "optionConfig": {
389
- "optionList": [
390
- { "label": "India", "code": "IN" },
391
- { "label": "USA", "code": "US" }
392
- ]
393
- }
394
- }
395
- ```
396
-
397
- #### Advanced Usage (Server-side Search & Rich Display)
398
-
399
- For large datasets, use `autocompleteConfig` to trigger server-side filtering and display rich metadata (emails, phones, avatars) in the dropdown options.
400
-
401
- ```json
402
- {
403
- "name": "responsiblePerson",
404
- "label": "Responsible Person",
405
- "type": "AUTOCOMPLETE",
406
- "optionConfig": {
407
- "apiUrl": "gateway/search-service/api/v1/users",
408
- "dataPath": "elements",
409
- "labelPath": "displayName",
410
- "valuePath": "userId"
411
- },
412
- "autocompleteConfig": {
413
- "method": "POST",
414
- "body": [],
415
- "searchParam": "searchTerm",
416
- "searchMinLength": 2,
417
- "displayFields": [
418
- { "path": "photoUrl", "type": "image" },
419
- { "path": "login", "type": "email", "label": "Email: " },
420
- { "path": "phone", "type": "phone" }
421
- ]
422
- }
423
- }
424
- ```
425
-
426
- #### Autocomplete Configuration (`autocompleteConfig`)
427
-
428
- | Property | Type | Description |
429
- | :--- | :--- | :--- |
430
- | `method` | `'GET' \| 'POST' \| 'PUT' \| 'PATCH'` | HTTP method for the search API (Default: `GET`). |
431
- | `body` | `any` | Static request body for `POST`/`PUT`/`PATCH` requests. |
432
- | `labelTemplate` | `string` | Template string for composite labels, e.g., `"{firstName} {lastName} ({empId})"`. |
433
- | `displayFields` | `string \| DisplayField[]` | Extra fields to show below the label. See [Rich Display Fields](#rich-display-fields). |
434
- | `searchParam` | `string` | Query parameter key sent to the API as the user types (e.g., `"q"` or `"searchTerm"`). |
435
- | `searchMinLength`| `number` | Minimum characters to type before firing an API request (Default: `1`). |
436
- | `searchDebounce` | `number` | Delay in ms before firing the search request (Default: `300ms`). |
437
-
438
- #### Rich Display Fields
439
-
440
- The `displayFields` property allows you to show extra information in the dropdown. Each field is rendered with an appropriate icon and style.
441
-
442
- | Type | Rendering |
443
- | :--- | :--- |
444
- | `text` | Plain secondary text (Default). |
445
- | `email` | Rendered with an envelope icon in a pill-style chip. |
446
- | `phone` | Rendered with a phone icon in a pill-style chip. |
447
- | `image` | Rendered as a small circular avatar/thumbnail. |
448
-
449
- #### Autocomplete Behaviour
450
-
451
- | Feature | Detail |
452
- | :--- | :--- |
453
- | **Debouncing** | Automatically waits for the user to stop typing before calling the API. |
454
- | **Syncing** | If the form is patched with a `code`, the component automatically fetches or resolves the `label` for display. |
455
- | **Edge Case Handling** | If a user types an invalid value and blurs, the input reverts to the last valid selection. |
456
- | **Clear Button** | A built-in "X" button allows users to reset the field instantly. |
457
-
458
- ### 4. Dropdown (DROPDOWN)
459
-
460
- **SubTypes:** `SINGLE`, `MULTIPLE`
461
-
462
- **Static options:**
463
-
464
- ```json
465
- {
466
- "name": "country",
467
- "label": "Country",
468
- "type": "DROPDOWN",
469
- "subType": "SINGLE",
470
- "required": true,
471
- "optionConfig": {
472
- "optionList": [
473
- { "label": "USA", "code": "US" },
474
- { "label": "Canada", "code": "CA" }
475
- ]
476
- }
477
- }
478
- ```
479
-
480
- **Load from API** (supports nested data paths):
481
-
482
- ```json
483
- {
484
- "name": "department",
485
- "label": "Department",
486
- "type": "DROPDOWN",
487
- "subType": "SINGLE",
488
- "optionConfig": {
489
- "apiUrl": "https://api.example.com/departments",
490
- "dataPath": "data.items",
491
- "labelPath": "profile.name",
492
- "valuePath": "meta.id"
493
- }
494
- }
495
- ```
496
-
497
- **Dependent Dropdown (Cascading Select):**
498
-
499
- ```json
500
- {
501
- "name": "state",
502
- "label": "State",
503
- "type": "DROPDOWN",
504
- "subType": "SINGLE",
505
- "optionConfig": {
506
- "apiUrl": "https://api.example.com/states",
507
- "valuePath": "code"
508
- }
509
- },
510
- {
511
- "name": "district",
512
- "label": "District",
513
- "type": "DROPDOWN",
514
- "subType": "SINGLE",
515
- "optionConfig": {
516
- "apiUrl": "https://api.example.com/districts",
517
- "dependencies": {
518
- "stateCode": "state"
519
- }
520
- }
521
- }
522
- ```
523
-
524
- `dependencies` maps API query-param keys to other field names. The parent field's current value is automatically appended to the API URL.
525
-
526
- **Merge Multiple APIs:**
527
-
528
- ```json
529
- {
530
- "name": "region",
531
- "label": "Region",
532
- "type": "DROPDOWN",
533
- "subType": "SINGLE",
534
- "optionConfig": {
535
- "apiUrls": [
536
- "https://api.example.com/states",
537
- "https://api.example.com/union-territories"
538
- ],
539
- "valuePath": "code",
540
- "labelPath": "name"
541
- }
542
- }
543
- ```
544
-
545
- **Sort Options:**
546
-
547
- ```json
548
- {
549
- "name": "country",
550
- "label": "Select Country",
551
- "type": "DROPDOWN",
552
- "subType": "SINGLE",
553
- "optionConfig": {
554
- "apiUrl": "https://api.example.com/countries",
555
- "valuePath": "code",
556
- "labelPath": "name.common",
557
- "sortBy": "name.common",
558
- "sortDirection": "ASC"
559
- }
560
- }
561
- ```
562
-
563
- **Searchable Dropdown (Local Filtering):**
564
-
565
- Add a search input inside the dropdown panel to filter options client-side. Works with both `SINGLE` and `MULTIPLE` subtypes.
566
-
567
- ```json
568
- {
569
- "name": "country",
570
- "label": "Select Country",
571
- "type": "DROPDOWN",
572
- "subType": "SINGLE",
573
- "optionConfig": {
574
- "apiUrl": "https://api.example.com/countries",
575
- "valuePath": "code",
576
- "labelPath": "name",
577
- "searchConfig": {
578
- "enabled": true
579
- }
580
- }
581
- }
582
- ```
583
-
584
- **Searchable Dropdown (Server-side Filtering via GET):**
585
-
586
- For large datasets, configure the dropdown to query the API as the user types. The search term is appended as a query parameter to the existing API URL.
587
-
588
- ```json
589
- {
590
- "name": "academicSubject",
591
- "label": "Academic Subject",
592
- "type": "DROPDOWN",
593
- "subType": "MULTIPLE",
594
- "optionConfig": {
595
- "apiUrl": "https://api.example.com/subjects",
596
- "dataPath": "elements",
597
- "labelPath": "name",
598
- "valuePath": "code",
599
- "searchConfig": {
600
- "enabled": true,
601
- "mode": "server",
602
- "searchKey": "searchTerm",
603
- "minSearchLength": 3,
604
- "debounceTime": 400
605
- }
606
- }
607
- }
608
- ```
609
-
610
- **Select All (Multi-Select Only):**
611
-
612
- For `MULTIPLE` dropdowns, add a "Select All" checkbox at the top of the option list. Can be combined with `searchConfig` — when a search filter is active, "Select All" toggles only the visible (filtered) options.
613
-
614
- ```json
615
- {
616
- "name": "skills",
617
- "label": "Skills",
618
- "type": "DROPDOWN",
619
- "subType": "MULTIPLE",
620
- "optionConfig": {
621
- "optionList": [
622
- { "label": "JavaScript", "code": "JS" },
623
- { "label": "Python", "code": "PY" },
624
- { "label": "Java", "code": "JAVA" },
625
- { "label": "Go", "code": "GO" }
626
- ],
627
- "showSelectAll": true,
628
- "searchConfig": {
629
- "enabled": true
630
- }
631
- }
632
- }
633
- ```
634
-
635
- #### Dropdown Search Configuration (`searchConfig`)
636
-
637
- | Property | Type | Default | Description |
638
- | :--- | :--- | :--- | :--- |
639
- | `enabled` | `boolean` | — | **Required.** Displays a search input inside the dropdown panel. |
640
- | `mode` | `'local' \| 'server'` | `'local'` | `local`: filters client-side. `server`: queries the API on typing via GET. |
641
- | `searchKey` | `string` | `'search'` | Query parameter key for the search term sent to the API. Only used in `server` mode. |
642
- | `minSearchLength` | `number` | `3` | Minimum characters required before triggering a server-side search. Only used in `server` mode. |
643
- | `debounceTime` | `number` | `300` | Debounce delay in milliseconds before firing the search. |
644
-
645
- #### Select All Configuration
646
-
647
- | Property | Type | Default | Description |
648
- | :--- | :--- | :--- | :--- |
649
- | `showSelectAll` | `boolean` | `false` | Renders a "Select All" checkbox at the top of a `MULTIPLE` select dropdown. |
650
-
651
- #### i18n Labels for Search & Select All
652
-
653
- The following label keys can be provided via the `labels` input to customise the UI text:
654
-
655
- | Key | Default | Description |
656
- | :--- | :--- | :--- |
657
- | `SEARCH_PLACEHOLDER` | `Search...` | Placeholder text for the search input. |
658
- | `SELECT_ALL` | `Select All` | Label for the Select All checkbox. |
659
- | `NO_MATCHING_OPTIONS` | `No options match your search` | Shown when the search filter yields no results. |
660
-
661
- ### 5. Radio Button (RADIO)
662
-
663
- ```json
664
- {
665
- "name": "gender",
666
- "label": "Gender",
667
- "type": "RADIO",
668
- "subType": "SINGLE",
669
- "required": true,
670
- "optionConfig": {
671
- "optionList": [
672
- { "label": "Male", "code": "M" },
673
- { "label": "Female", "code": "F" }
674
- ]
675
- }
676
- }
677
- ```
678
-
679
- ### 6. Checkbox (CHECKBOX)
680
-
681
- **SubTypes:** `BOOL`, `LIST`
682
-
683
- ```json
684
- {
685
- "name": "agreeToTerms",
686
- "label": "I agree to terms",
687
- "type": "CHECKBOX",
688
- "subType": "BOOL",
689
- "required": true
690
- }
691
- ```
692
-
693
- ### 7. Chip Selection (CHIP)
694
-
695
- ```json
696
- {
697
- "name": "skills",
698
- "label": "Skills",
699
- "type": "CHIP",
700
- "subType": "MULTIPLE",
701
- "optionConfig": {
702
- "optionList": [
703
- { "label": "JavaScript", "code": "JS" },
704
- { "label": "Python", "code": "PY" }
705
- ]
706
- }
707
- }
708
- ```
709
-
710
- ### 8. Switch (SWITCH)
711
-
712
- ```json
713
- {
714
- "name": "notifications",
715
- "label": "Enable Notifications",
716
- "type": "SWITCH",
717
- "subType": "BOOL",
718
- "defaultValue": true
719
- }
720
- ```
721
-
722
- ### 9. Rating (RATING)
723
-
724
- ```json
725
- {
726
- "name": "rating",
727
- "label": "Rate your experience",
728
- "type": "RATING",
729
- "subType": "STAR",
730
- "ratingConfig": {
731
- "maxRating": 5,
732
- "allowHalf": true
733
- }
734
- }
735
- ```
736
-
737
- ### 10. File Upload (FILE_UPLOAD)
738
-
739
- Provides a drag-and-drop area with file-type and file-size validation. The field value is an array of `UploadedFile` objects. This field uses a unified `attachmentConfig` for all upload types (PDF, Images, Documents, etc.).
740
-
741
- **SubTypes:** `SINGLE`
742
-
743
- ```json
744
- {
745
- "name": "profilePicture",
746
- "label": "Profile Picture",
747
- "type": "FILE_UPLOAD",
748
- "subType": "SINGLE",
749
- "attachmentConfig": {
750
- "multiple": false,
751
- "maxSizeMB": 2,
752
- "accept": "image/*",
753
- "acceptLabel": "JPG, PNG, SVG (max 2 MB)"
754
- }
755
- }
756
- ```
757
-
758
- | `attachmentConfig` key | Type | Description |
759
- | ---------------------- | ------- | ------------------------------------------------------------ |
760
- | `multiple` | boolean | Allow multiple file selection (default: `false`) |
761
- | `maxFiles` | number | Max number of files when `multiple: true` (default: `10`) |
762
- | `maxSizeMB` | number | Max file size per file in MB (default: `10`) |
763
- | `accept` | string | Accepted MIME types / extensions, e.g. `".pdf,.jpg,image/*"` |
764
- | `acceptLabel` | string | Human-readable hint shown in the drop zone |
765
-
766
- ### 11. Generated Field (GENERATED)
767
-
768
- Auto-calculated fields that update whenever dependent field values change.
769
-
770
- ```json
771
- {
772
- "name": "fullName",
773
- "label": "Full Name",
774
- "type": "GENERATED",
775
- "subType": "FORMULA",
776
- "generatedConfig": {
777
- "formula": "function fullName(first, last) { return (first || '') + ' ' + (last || ''); }",
778
- "variables": ["firstName", "lastName"]
779
- }
780
- }
781
- ```
782
-
783
- ### 12. Geography Dynamic (GEOGRAPHY_DYNAMIC)
784
-
785
- Renders a cascading hierarchy of geography dropdowns (e.g. Country → State → District) by fetching a hierarchy template from an MDM API. When the hierarchy has a **branch point** (e.g. State → RURAL | URABN), an **Area Type** selector is automatically inserted so the user can choose which path to follow.
786
-
787
- **Branch point behavior**
788
-
789
- - The Area Type dropdown is generated automatically from the branch children (e.g. "Rural" / "Urban").
790
- - Selecting a branch value shows only the dropdowns belonging to that path (District, Taluka, Village …).
791
- - Structural branch-type nodes (RURAL, URABN) are **not** rendered as data dropdowns — only their descendants are. The first descendant depends on the last linear parent before the fork (e.g. State), not on the branch node itself.
792
- - If the form is pre-populated with an `areaType` value (edit mode), the downstream dropdowns are visible immediately.
793
-
794
- ```json
795
- {
796
- "name": "address",
797
- "label": "Address",
798
- "type": "GEOGRAPHY_DYNAMIC",
799
- "geographyConfig": {
800
- "templateApi": {
801
- "apiUrl": "https://api.example.com/mdm/hierarchy-templates",
802
- "listPath": "templates",
803
- "select": "byCode",
804
- "selectCode": "ADDRESS_TEMPLATE"
805
- },
806
- "dataApi": {
807
- "apiUrl": "https://api.example.com/mdm/data/{classCode}",
808
- "dataPath": "elements",
809
- "labelPath": "name[0].text",
810
- "valuePath": "code"
811
- },
812
- "structure": {
813
- "rootCodePath": "rootClassCode",
814
- "hierarchyListPath": "mdmclasshierarchytemplatestructList",
815
- "parentField": "parentCode",
816
- "childField": "childCode"
817
- },
818
- "field": {
819
- "colSpan": 4,
820
- "payloadPathPrefix": "addressInfo",
821
- "branchSubType": "SINGLE",
822
- "dependency": {
823
- "paramName": "parentDataCode"
824
- },
825
- "nodes": {
826
- "REGION.COUNTRY": { "label": "Country", "required": true },
827
- "REGION.STATE": { "label": "State", "payloadField": "stateCode" }
828
- }
829
- }
830
- }
831
- }
832
- ```
833
-
834
- **`field` configuration keys**
835
-
836
- | Key | Type | Default | Description |
837
- |---|---|---|---|
838
- | `colSpan` | `number` | `12` | Column span applied to every generated dropdown |
839
- | `payloadPathPrefix` | `string` | `''` | Dot-notation prefix prepended to all generated `payloadPath` values |
840
- | `branchSubType` | `'SINGLE' \| 'MULTIPLE'` | `'SINGLE'` | Sub-type for the auto-generated Area Type selector |
841
- | `dependency.paramName` | `string` | `'parentDataCode'` | Query parameter name sent when loading child data |
842
- | `nodes` | `Record<string, object>` | `{}` | Per-node overrides keyed by class code — supports `label`, `name`, `payloadField`, `required`, `placeholder`, `hidden`, `noDependency` |
843
-
844
- ### 13. Rich Text Editor (RICH_TEXT)
845
-
846
- Provides a WYSIWYG rich text editor using Quill.
847
-
848
- ```json
849
- {
850
- "name": "description",
851
- "label": "Detailed Description",
852
- "type": "RICH_TEXT",
853
- "required": true,
854
- "richTextConfig": {
855
- "placeholder": "Enter detailed information here...",
856
- "height": "250px",
857
- "headerConfig": ["bold", "italic", "underline", "font", "size", "color", "link", "image", "video"]
858
- }
859
- }
860
- ```
861
-
862
- `headerConfig` controls which toolbar buttons are shown, in order. If omitted, it defaults to:
863
- `["bold", "italic", "underline", "font", "size", "color", "link", "image", "video"]`.
864
-
865
- Supported tokens: `bold`, `italic`, `underline`, `strike`, `blockquote`, `code`, `font`, `size`, `color`, `background`, `align`, `header1`, `header2`, `orderedList`, `bulletList`, `subscript`, `superscript`, `indentMinus`, `indentPlus`, `link`, `image`, `video`, `clean`.
866
-
867
- ---
868
-
869
- ## Layout System
870
-
871
- ### ROW Layout
872
-
873
- Use `type: "ROW"` to place multiple fields horizontally in a 12-column CSS grid. Each child can declare a `colSpan` (1–12). If omitted, the available columns are divided equally among all children.
874
-
875
- ```json
876
- {
877
- "type": "ROW",
878
- "subType": "HORIZONTAL",
879
- "children": [
880
- {
881
- "name": "firstName",
882
- "label": "First Name",
883
- "type": "TEXT_INPUT",
884
- "subType": "SHORT",
885
- "colSpan": 6
886
- },
887
- {
888
- "name": "lastName",
889
- "label": "Last Name",
890
- "type": "TEXT_INPUT",
891
- "subType": "SHORT",
892
- "colSpan": 6
893
- }
894
- ]
895
- }
896
- ```
897
-
898
- ### `colSpan` on Section-level Fields
899
-
900
- A non-ROW field that is a direct child of a section can also carry a `colSpan` to participate in the section-level 12-column grid:
901
-
902
- ```json
903
- {
904
- "name": "description",
905
- "label": "Description",
906
- "type": "TEXT_INPUT",
907
- "subType": "LONG",
908
- "colSpan": 8
909
- }
910
- ```
911
-
912
- ### `colSpan` Reference
913
-
914
- | `colSpan` value | Effective width |
915
- | --------------- | --------------- |
916
- | 3 | 25% |
917
- | 4 | 33% |
918
- | 6 | 50% |
919
- | 8 | 67% |
920
- | 9 | 75% |
921
- | 12 (default) | 100% |
922
-
923
- ---
924
-
925
- ## Configuration Options
926
-
927
- ### Form Schema
928
-
929
- ```typescript
930
- interface FormSchema {
931
- entityType: string;
932
- label: string; // Can be an i18n key
933
- formType: "SECTION" | "STEPPER";
934
- showTitle?: boolean;
935
- showDescription?: boolean;
936
- description?: string; // Can be an i18n key
937
- metadata?: { [key: string]: any };
938
- sectionConfig?: SectionConfig;
939
- stepperConfig?: StepperConfig;
940
- submitConfig?: SubmitConfig;
941
- editConfig?: EditConfig; // Config for form editing (GET to load, PATCH/PUT to submit)
942
- actionBarConfig?: ActionBarConfig; // Flexible action bar (Cancel / Draft / Submit)
943
- showActions?: boolean;
944
- token?: string; // Full auth token (e.g. "Bearer eyJ…") — applied to all API calls
945
- tokenHeader?: string; // HTTP header name (default: "Authorization")
946
- }
947
- ```
948
-
949
- ### Action Bar Config
950
-
951
- The `actionBarConfig` defines the buttons rendered at the bottom of the form. It uses a **unified, flexible list of buttons** where each button has its own visual style and behavior-driven action.
952
-
953
- #### Unified Button Model
954
-
955
- In the new model, a button is **only visual** (label, variant, alignment, order). All logic (what happens when clicked) is delegated to an `action` object of type `ActionConfig`.
956
-
957
- | Action `kind` | Behaviour |
958
- |---------------|-----------|
959
- | `'submit'` | Validates the form and calls the central `submitConfig` or `editConfig` API. |
960
- | `'draft'` | Saves the form data without full validation. Merges `extraPayload` if provided. |
961
- | `'navigate'` | Simply navigates to the `redirectUrl`. No API call. |
962
- | `'api'` | Fires a standalone API call (`apiUrl`, `method`), then optionally navigates. |
963
- | `'emit'` | Emits the `actionClick` output event with the button `id` and form data. |
964
- | `'next'` | Advances to the next step (Stepper forms only). |
965
- | `'prev'` | Goes back to the previous step (Stepper forms only). |
966
-
967
- #### Interfaces
968
-
969
- ```typescript
970
- interface ActionBarConfig {
971
- /** Explicitly ordered list of action buttons. */
972
- buttons: ActionButtonConfig[];
973
- }
974
-
975
- interface ActionButtonConfig {
976
- id: string; // Unique identifier for the button
977
- label?: string; // i18n key or plain text
978
- variant?: string; // lib-button variant (primary, outline, etc.)
979
- alignment?: 'left'|'right'; // Which side of the bar to place the button (default: 'right')
980
- order?: number; // Display order within the alignment group
981
- hidden?: boolean; // Hide the button
982
- disabled?: boolean; // Disable the button
983
- showOnLastStepOnly?: boolean; // Section Stepper only: show this button only on the last step
984
- action: ActionConfig; // The behavior triggered on click
985
- }
986
-
987
- interface ActionConfig {
988
- kind: 'submit' | 'draft' | 'navigate' | 'api' | 'emit' | 'next' | 'prev';
989
- redirectUrl?: string; // Used by 'navigate', 'api', 'draft', and 'submit'
990
- apiUrl?: string; // Required for 'api' kind
991
- method?: string; // HTTP method for 'api' actions (default: 'POST')
992
- extraPayload?: object; // Static payload for 'api' or 'draft' saves
993
- successMessage?: string; // Custom success snackbar message
994
- errorMessage?: string; // Custom error snackbar message
995
- snackbarConfig?: object; // Snackbar display options
996
- }
997
- ```
998
-
999
- #### Example — Standard Cancel, Draft, and Submit
1000
-
1001
- This configuration places a "Cancel" button on the left that navigates away, and "Save as Draft" + "Submit" buttons on the right.
1002
-
1003
- ```json
1004
- {
1005
- "actionBarConfig": {
1006
- "buttons": [
1007
- {
1008
- "id": "cancel",
1009
- "label": "Cancel",
1010
- "variant": "outline",
1011
- "alignment": "left",
1012
- "action": { "kind": "navigate", "redirectUrl": "/dashboard" }
1013
- },
1014
- {
1015
- "id": "draft",
1016
- "label": "Save as Draft",
1017
- "variant": "secondary",
1018
- "alignment": "right",
1019
- "action": { "kind": "draft", "extraPayload": { "status": "DRAFT" } }
1020
- },
1021
- {
1022
- "id": "submit",
1023
- "label": "Submit",
1024
- "variant": "primary",
1025
- "alignment": "right",
1026
- "action": { "kind": "submit" }
1027
- }
1028
- ]
1029
- }
1030
- }
1031
- ```
1032
-
1033
- #### Example — Stepper with Back/Next and a Custom Finish Button
1034
-
1035
- ```json
1036
- {
1037
- "actionBarConfig": {
1038
- "buttons": [
1039
- {
1040
- "id": "back",
1041
- "label": "Back",
1042
- "alignment": "left",
1043
- "action": { "kind": "prev" }
1044
- },
1045
- {
1046
- "id": "save-and-exit",
1047
- "label": "Save & Exit",
1048
- "alignment": "right",
1049
- "variant": "outline",
1050
- "action": { "kind": "api", "apiUrl": "/api/v1/sessions/save-progress" }
1051
- },
1052
- {
1053
- "id": "next",
1054
- "label": "Next Step",
1055
- "alignment": "right",
1056
- "variant": "primary",
1057
- "action": { "kind": "submit" }
1058
- }
1059
- ]
1060
- }
1061
- }
1062
- ```
1063
-
1064
- #### Notes
1065
-
1066
- - **Alignment**: Buttons with `alignment: 'left'` are grouped on the left side. `alignment: 'right'` (the default) are on the right. Both groups use `flexbox` for layout, pushing them to opposite edges of the form.
1067
- - **Ordering**: Within each side, buttons are sorted by the `order` property (numeric, ascending). If `order` is omitted, they appear in the order defined in the JSON array.
1068
- - **Custom Actions**: Use `kind: 'emit'` to handle logic in your parent component. Whenever clicked, the `<lib-smart-form>` will emit an `(actionClick)` event containing the button's `id` and the current form data.
1069
- - **Draft Behavior**: Just like the legacy mode, `'kind': 'draft'` skips required field validation and collects whatever data is currently in the form.
1070
- - **`showOnLastStepOnly`**: When `true` and the form is in **Section Stepper** mode, the button is hidden on all intermediate steps and only appears on the last step. Has no effect in regular (non-stepper) layouts — the button always shows there. Ideal for Submit buttons that should not be reachable until the user has navigated through all steps.
1071
-
1072
- ### Section Config
1073
-
1074
- ```typescript
1075
- interface SectionConfig {
1076
- children: FieldConfig[];
1077
- allowMulti?: boolean; // Enables repeater mode — see Repeatable Sections
1078
- name?: string; // Required when allowMulti is true (used as FormArray key)
1079
- label?: string; // Can be an i18n key
1080
- isEnabled?: boolean; // Static flag to explicitly hide the entire section if false
1081
- }
1082
- ```
1083
-
1084
- ### Submit & Edit Configs
1085
-
1086
- ```typescript
1087
- interface SubmitConfig {
1088
- apiUrl: string;
1089
- method?: "POST" | "PUT" | "PATCH";
1090
- successMessage?: string; // Can be an i18n key
1091
- errorMessage?: string; // Can be an i18n key
1092
- redirectUrl?: string; // Redirect after success
1093
- extraPayload?: { [key: string]: any }; // Static extra fields for payload
1094
- snackbarConfig?: SnackbarConfigOverride; // Customizes the API feedback alerts
1095
- }
1096
-
1097
- interface EditConfig {
1098
- loadApiUrl: string; // Custom GET API to load existing form data
1099
- submitApiUrl: string; // PATCH/PUT/POST API for updating
1100
- submitMethod?: "PATCH" | "PUT" | "POST";
1101
- successMessage?: string;
1102
- errorMessage?: string;
1103
- redirectUrl?: string;
1104
- extraPayload?: { [key: string]: any };
1105
- snackbarConfig?: SnackbarConfigOverride;
1106
- }
1107
-
1108
- interface SnackbarConfigOverride {
1109
- duration?: number; // Auto-dismiss time (default 5000)
1110
- horizontalPosition?: "start" | "center" | "end" | "left" | "right";
1111
- verticalPosition?: "top" | "bottom";
1112
- showCloseButton?: boolean;
1113
- }
1114
- ```
1115
-
1116
- ### Field Config (key properties)
1117
-
1118
- ```typescript
1119
- interface FieldConfig {
1120
- name?: string;
1121
- label?: string; // Can be an i18n key
1122
- type: string;
1123
- subType: string;
1124
- required?: boolean;
1125
- disabled?: boolean;
1126
- defaultValue?: any;
1127
- placeholder?: string; // Can be an i18n key
1128
- hint?: string; // Can be an i18n key
1129
- colSpan?: number; // Column span in 12-column grid (1–12)
1130
- payloadPath?: string; // Dot-notation path for nested payload mapping (e.g., 'status.code')
1131
- visibilityExpression?: string;
1132
- isEnabled?: boolean; // Static flag to explicitly disable/hide the field if false
1133
- readonly?: boolean; // Whether the field is read-only (shows lock icon)
1134
- suffixActionIcons?: SuffixActionIcon[]; // Clickable action icons inside the input
1135
- sectionConfig?: SectionConfig;
1136
- textConfig?: TextConfig;
1137
- numberConfig?: NumberConfig;
1138
- dateConfig?: DateConfig;
1139
- timeConfig?: TimeConfig;
1140
- optionConfig?: OptionConfig;
1141
- attachmentConfig?: AttachmentConfig;
1142
- ratingConfig?: RatingConfig;
1143
- generatedConfig?: GeneratedConfig;
1144
- richTextConfig?: RichTextConfig;
1145
- children?: FieldConfig[]; // For ROW and GROUP fields
1146
- }
1147
-
1148
- interface SuffixActionIcon {
1149
- icon: string; // Material icon name (e.g. 'edit', 'refresh')
1150
- actionId: string; // Unique ID emitted on click
1151
- tooltip?: string; // Optional tooltip shown on hover
1152
- color?: string; // Optional custom color override (e.g. '#16A34A')
1153
- }
1154
-
1155
- interface AttachmentConfig {
1156
- multiple?: boolean;
1157
- maxFiles?: number;
1158
- maxSizeMB?: number;
1159
- accept?: string;
1160
- acceptLabel?: string;
1161
- allowedExtensions?: string[]; // Legacy
1162
- }
1163
-
1164
- interface RichTextConfig {
1165
- height?: string; // CSS height for the editor (e.g. "200px")
1166
- placeholder?: string; // Custom placeholder text
1167
- maxLength?: number;
1168
- showCharCount?: boolean;
1169
- headerConfig?: string[]; // Toolbar tokens to show, in order (default: bold/italic/underline/font/size/color/link/image/video)
1170
- }
1171
- ```
1172
-
1173
- ---
1174
-
1175
- ## Advanced Features
1176
-
1177
- ### 1. Conditional Visibility
1178
-
1179
- Show/hide fields based on other field values using a JavaScript-like expression:
1180
-
1181
- ```json
1182
- {
1183
- "name": "otherReason",
1184
- "label": "Please specify",
1185
- "type": "TEXT_INPUT",
1186
- "subType": "SHORT",
1187
- "visibilityExpression": "reason === 'OTHER'",
1188
- "required": true
1189
- }
1190
- ```
1191
-
1192
- The expression is evaluated against the live form data. When a field is hidden its control is disabled so its value is excluded from submission.
1193
-
1194
- ### 2. Auto-Calculated Fields
1195
-
1196
- Fields that automatically update based on other fields:
1197
-
1198
- ```json
1199
- {
1200
- "name": "total",
1201
- "label": "Total Amount",
1202
- "type": "GENERATED",
1203
- "subType": "FORMULA",
1204
- "generatedConfig": {
1205
- "formula": "function total(price, quantity) { return (price || 0) * (quantity || 0); }",
1206
- "variables": ["price", "quantity"]
1207
- }
1208
- }
1209
- ```
1210
-
1211
- ### 3. Repeatable Sections (`allowMulti` on GROUP)
1212
-
1213
- Allow users to add multiple instances of a section (e.g., multiple work experiences):
1214
-
1215
- ```json
1216
- {
1217
- "type": "GROUP",
1218
- "subType": "SECTION",
1219
- "sectionConfig": {
1220
- "label": "Work Experience",
1221
- "allowMulti": true,
1222
- "name": "experienceList",
1223
- "children": [
1224
- {
1225
- "name": "company",
1226
- "label": "Company",
1227
- "type": "TEXT_INPUT",
1228
- "subType": "SHORT",
1229
- "required": true
1230
- },
1231
- {
1232
- "name": "position",
1233
- "label": "Position",
1234
- "type": "TEXT_INPUT",
1235
- "subType": "SHORT",
1236
- "required": true
1237
- }
1238
- ]
1239
- }
1240
- }
1241
- ```
1242
-
1243
- - `name` is **required** when `allowMulti: true` — it becomes the `FormArray` key on the root `FormGroup`.
1244
- - Each instance is a completely isolated `FormGroup`; data does not leak between instances.
1245
- - The submitted value for this key is an **array of objects**, e.g. `{ "experienceList": [{ "company": "...", "position": "..." }, ...] }`.
1246
-
1247
- ### 4. Cross-Field Match Validation (e.g. confirm password)
1248
-
1249
- Use `textConfig.matchField` on the confirmation field to enforce equality:
1250
-
1251
- ```json
1252
- {
1253
- "name": "confirmPassword",
1254
- "label": "Confirm Password",
1255
- "type": "TEXT_INPUT",
1256
- "subType": "PASSWORD",
1257
- "required": true,
1258
- "textConfig": { "matchField": "password" }
1259
- }
1260
- ```
1261
-
1262
- - Validation fires bi-directionally: if the user edits the source field after confirming, the error clears automatically.
1263
- - Error key: `passwordMismatch`, shown as "Passwords do not match".
1264
-
1265
- ### 5. Row Layouts with Column Spans
1266
-
1267
- Display multiple fields in a row with fine-grained width control:
1268
-
1269
- ```json
1270
- {
1271
- "type": "ROW",
1272
- "subType": "HORIZONTAL",
1273
- "children": [
1274
- {
1275
- "name": "shortCode",
1276
- "label": "Short Code",
1277
- "type": "TEXT_INPUT",
1278
- "subType": "SHORT",
1279
- "colSpan": 3
1280
- },
1281
- {
1282
- "name": "donorType",
1283
- "label": "Donor Type",
1284
- "type": "DROPDOWN",
1285
- "subType": "SINGLE",
1286
- "colSpan": 3
1287
- },
1288
- {
1289
- "name": "regNumber",
1290
- "label": "Reg. Number",
1291
- "type": "TEXT_INPUT",
1292
- "subType": "SHORT",
1293
- "colSpan": 3
1294
- },
1295
- {
1296
- "name": "country",
1297
- "label": "Country",
1298
- "type": "DROPDOWN",
1299
- "subType": "SINGLE",
1300
- "colSpan": 3
1301
- }
1302
- ]
1303
- }
1304
- ```
1305
-
1306
- ### 6. Suffix Action Icons
1307
-
1308
- Add clickable action icons inside `TEXT_INPUT` (short text, email, phone) and `NUMBER_INPUT` fields to trigger custom logic in the host application (e.g. password visibility toggling, code validation, API lookup).
1309
-
1310
- ```json
1311
- {
1312
- "name": "promoCode",
1313
- "label": "PROMO_CODE.LABEL",
1314
- "type": "TEXT_INPUT",
1315
- "subType": "SHORT",
1316
- "suffixActionIcons": [
1317
- {
1318
- "icon": "refresh",
1319
- "actionId": "regenerate_code",
1320
- "tooltip": "Regenerate Promo Code",
1321
- "color": "#1E3A8A"
1322
- },
1323
- {
1324
- "icon": "check_circle",
1325
- "actionId": "verify_code",
1326
- "tooltip": "Verify Validity",
1327
- "color": "#16A34A"
1328
- }
1329
- ]
1330
- }
1331
- ```
1332
-
1333
- When clicked, the `(suffixActionClick)` output event is emitted. The host application catches this event to run specific actions (such as generating a new promo code or verifying its validity).
1334
-
1335
- > [!NOTE]
1336
- > Suffix action icons are ignored if the field is set to `readonly: true`. In that state, the default security lock icon (`lock`) takes visual precedence.
1337
-
1338
- ---
1339
-
1340
- ## i18n / Translation Support
1341
-
1342
- The `SmartFormComponent` accepts a `[labels]` input that is a **flat key–value map** of i18n strings (or an object with a `labelsObject` property following the same pattern used by `ConfigurableFormComponent`).
1343
-
1344
- When `labels` is provided, the component recursively walks the parsed schema **before rendering** and replaces every matching key with its translated value.
1345
-
1346
- ### Action Labels
1347
-
1348
- The form action buttons (Next, Submit, Previous, Add, Remove) and file upload error messages can be localized by providing keys in the `labels` property of the `FormSchema`.
1349
-
1350
- ```json
1351
- {
1352
- "entityType": "USER",
1353
- "label": "FORM.TITLE",
1354
- "formType": "SECTION",
1355
- "labels": {
1356
- "nextLabel": "APP.BUTTON.NEXT",
1357
- "submitLabel": "APP.BUTTON.SUBMIT",
1358
- "previousLabel": "APP.BUTTON.PREVIOUS",
1359
- "addLabel": "APP.BUTTON.ADD",
1360
- "removeLabel": "APP.BUTTON.REMOVE",
1361
- "fileTypeError": "\"{fileName}\" is not a supported file type.",
1362
- "fileSizeError": "\"{fileName}\" exceeds the maximum allowed size of {maxSizeMB} MB.",
1363
- "maxFilesError": "Maximum {maxFiles} files allowed.",
1364
- "fileUploadFailed": "Failed to upload \"{fileName}\". Please try again.",
1365
- "fileDeleteFailed": "Failed to delete \"{fileName}\". Please try again."
1366
- }
1367
- }
1368
- ```
1369
-
1370
- If a mapping is not provided, the buttons and messages fall back to default English strings.
1371
-
1372
- **File upload label placeholders**
1373
-
1374
- | Label key | Dynamic placeholders | Default English text |
1375
- |---|---|---|
1376
- | `fileTypeError` | `{fileName}` | `"{fileName}" is not a supported file type.` |
1377
- | `fileSizeError` | `{fileName}`, `{maxSizeMB}` | `"{fileName}" exceeds the maximum allowed size of {maxSizeMB} MB.` |
1378
- | `maxFilesError` | `{maxFiles}` | `Maximum {maxFiles} files allowed.` |
1379
- | `fileUploadFailed` | `{fileName}` | `Failed to upload "{fileName}". Please try again.` |
1380
- | `fileDeleteFailed` | `{fileName}` | `Failed to delete "{fileName}". Please try again.` |
1381
-
1382
- ### Translatable Schema Properties
1383
-
1384
- | Property path | Description |
1385
- | --------------------------------------- | ---------------------------------------------- |
1386
- | `schema.label` | Form title |
1387
- | `schema.description` | Form description |
1388
- | `schema.submitConfig.successMessage` | Success alert text |
1389
- | `schema.submitConfig.errorMessage` | Error alert text |
1390
- | `sectionConfig.label` | Section heading |
1391
- | `field.label` | Field label |
1392
- | `field.placeholder` | Field placeholder |
1393
- | `field.hint` | Field hint text |
1394
- | `field.textConfig.patternMessage` | Custom pattern error message |
1395
- | `field.attachmentConfig.acceptLabel` | File drop-zone hint (for all attachment types) |
1396
- | `field.optionConfig.optionList[].label` | Static option labels |
1397
- | `schema.labels.nextLabel` | Key for "Next" button text (Stepper) |
1398
- | `schema.labels.submitLabel` | Key for "Submit" button text |
1399
- | `schema.labels.previousLabel` | Key for "Previous" button text (Stepper) |
1400
- | `schema.labels.addLabel` | Key for "Add" button text (Repeater) |
1401
- | `schema.labels.removeLabel` | Key for "Remove" button text (Repeater) |
1402
- | `schema.labels.fileTypeError` | File upload: unsupported file type error |
1403
- | `schema.labels.fileSizeError` | File upload: file too large error |
1404
- | `schema.labels.maxFilesError` | File upload: too many files error |
1405
- | `schema.labels.fileUploadFailed` | File upload: API upload failure message |
1406
- | `schema.labels.fileDeleteFailed` | File upload: API delete failure message |
1407
-
1408
- > **Note:** Translation logic is centralized in the `SmartFormTranslationUtils` class. If you add new translatable properties to the `FormSchema` or `FieldConfig` models, ensure they are also registered in the `SmartFormTranslationUtils.translateSchema` method to be correctly processed.
1409
-
1410
- Translation is applied recursively — it covers fields inside `ROW` children, `GROUP` children, nested `sectionConfig` sections, and all stepper steps.
1411
-
1412
- ### Usage
1413
-
1414
- ```html
1415
- <lib-smart-form
1416
- [formJson]="formJson"
1417
- [labels]="labels"
1418
- (submit)="onSubmit($event)"
1419
- >
1420
- </lib-smart-form>
1421
- ```
1422
-
1423
- ```typescript
1424
- // Flat map — keys exactly match the strings used in the JSON schema
1425
- labels = {
1426
- "SMART_FORM.TITLE": "User Registration",
1427
- "SMART_FORM.FIELD.FIRST_NAME": "First Name",
1428
- "SMART_FORM.PH.FIRST_NAME": "Enter your first name",
1429
- };
1430
- ```
1431
-
1432
- When `labels` changes (e.g., user switches language), the form is automatically re-parsed and all labels are re-translated.
1433
-
1434
- ### Compatibility with `labelsObject`
1435
-
1436
- The component also accepts the pattern used by `ConfigurableFormComponent`:
1437
-
1438
- ```typescript
1439
- labels = {
1440
- errorMaxItemsAllowed: "...",
1441
- labelsObject: { "SMART_FORM.TITLE": "User Registration" /* ... */ },
1442
- };
1443
- ```
1444
-
1445
- If `labels.labelsObject` is present, translations are read from there; otherwise the top-level object is used directly.
1446
-
1447
- ---
1448
-
1449
- ## API Submission
1450
-
1451
- ### Automatic API Submission (CREATE / POST)
1452
-
1453
- Configure the form to automatically submit to an API endpoint by providing a `submitConfig`. You can also provide static additional payload fields that the form will merge into the final API request.
1454
-
1455
- ```json
1456
- {
1457
- "entityType": "USER",
1458
- "submitConfig": {
1459
- "apiUrl": "https://api.example.com/users",
1460
- "method": "POST",
1461
- "successMessage": "User created successfully!",
1462
- "redirectUrl": "https://platformcommons.dev/home",
1463
- "extraPayload": {
1464
- "channelCode": "CHANNEL.COMMONS.GRE_DEFAULT_CHANNEL",
1465
- "marketCode": "COMMONS.GRE",
1466
- "status": {
1467
- "code": "REQUEST_STATUS.SUBMITTED"
1468
- }
1469
- }
1470
- }
1471
- }
1472
- ```
1473
-
1474
- ### Form Editing (EDIT / PATCH)
1475
-
1476
- To support editing an existing record, switch the SmartFormComponent mode to `EDIT` and provide an `editConfig` in the `FormSchema`. The component will fetch the existing data using `loadApiUrl` before the form renders, and submit changes to `submitApiUrl` using the defined `submitMethod` (default `PATCH`).
1477
-
1478
- ```html
1479
- <lib-smart-form [formJson]="formJson" mode="EDIT" (submit)="onSubmit($event)">
1480
- </lib-smart-form>
1481
- ```
1482
-
1483
- ```json
1484
- {
1485
- "entityType": "USER",
1486
- "editConfig": {
1487
- "loadApiUrl": "https://api.example.com/users/123",
1488
- "submitApiUrl": "https://api.example.com/users/123",
1489
- "submitMethod": "PATCH",
1490
- "successMessage": "User updated successfully!",
1491
- "redirectUrl": "https://platformcommons.dev/home",
1492
- "extraPayload": {
1493
- "updatedBy": "admin"
1494
- }
1495
- }
1496
- }
1497
- ```
1498
-
1499
- ### Nested Payload Mapping
1500
-
1501
- By default, the form submits a flat object matching the field names. If your API requires nested structures (like `status.code` or `address.city`), specify the nested hierarchy using the `payloadPath` property on the `FieldConfig`.
1502
-
1503
- ```json
1504
- {
1505
- "name": "statusCodeInput",
1506
- "label": "Status",
1507
- "type": "TEXT_INPUT",
1508
- "subType": "SHORT",
1509
- "payloadPath": "status.code"
1510
- }
1511
- ```
1512
-
1513
- Upon submission, the value from `statusCodeInput` will be formatted as:
1514
-
1515
- ```json
1516
- {
1517
- "status": {
1518
- "code": "Submitted value"
1519
- }
1520
- }
1521
- ```
1522
-
1523
- **Array Support in Payload Mapping:**
1524
- You can also specify array indices directly in the `payloadPath` if your API expects values inside nested arrays.
1525
-
1526
- ```json
1527
- {
1528
- "name": "firstName",
1529
- "label": "First Name",
1530
- "type": "TEXT_INPUT",
1531
- "subType": "SHORT",
1532
- "payloadPath": "name[0].labels.text"
1533
- }
1534
- ```
1535
-
1536
- Upon submission, the value from `firstName` will be formatted as:
1537
-
1538
- ```json
1539
- {
1540
- "name": [
1541
- {
1542
- "labels": {
1543
- "text": "Submitted value"
1544
- }
1545
- }
1546
- ]
1547
- }
1548
- ```
1549
-
1550
- ### Deep-Merging with `extraPayload`
1551
-
1552
- The `SmartFormComponent` intelligently deep-merges anything you provide in `submitConfig.extraPayload` (or `editConfig.extraPayload`) with the payload constructed from the form fields.
1553
-
1554
- This means you can provide static extra properties that share the same nested structure (even arrays), and they will perfectly overlay each other.
1555
-
1556
- **Example: Merging Array Values**
1557
- Using the `firstName` setup above, if you needed your API payload to look like this:
1558
-
1559
- ```json
1560
- {
1561
- "name": [
1562
- {
1563
- "id": 0,
1564
- "labels": {
1565
- "text": "John"
1566
- }
1567
- }
1568
- ]
1569
- }
1570
- ```
1571
-
1572
- You simply put the static `"id": 0` inside your `extraPayload` mirroring the structure:
1573
-
1574
- ```json
1575
- {
1576
- "entityType": "USER",
1577
- "submitConfig": {
1578
- "apiUrl": "https://api.example.com/users",
1579
- "extraPayload": {
1580
- "name": [
1581
- {
1582
- "id": 0
1583
- }
1584
- ]
1585
- }
1586
- },
1587
- "sectionConfig": {
1588
- "children": [
1589
- {
1590
- "name": "firstName",
1591
- "payloadPath": "name[0].labels.text",
1592
- "type": "TEXT_INPUT"
1593
- }
1594
- ]
1595
- }
1596
- }
1597
- ```
1598
-
1599
- The internal deep-merge algorithm combines the values at `name[0]` to produce the exact desired payload.
1600
-
1601
- "label": "User Registration",
1602
- "formType": "SECTION",
1603
- "submitConfig": {
1604
- "apiUrl": "https://api.example.com/users",
1605
- "method": "POST",
1606
- "successMessage": "User created successfully",
1607
- "errorMessage": "Failed to create user"
1608
- },
1609
- "sectionConfig": { "children": [...] }
1610
- }
1611
-
1612
- ````
1613
-
1614
- ### Manual Submission
1615
-
1616
- If no `submitConfig` is provided, handle submission in the parent component via the `(submit)` output:
1617
-
1618
- ```typescript
1619
- onSubmit(data: any) {
1620
- this.http.post("https://api.example.com/users", data).subscribe(
1621
- response => console.log("Success", response),
1622
- error => console.error("Error", error)
1623
- );
1624
- }
1625
- ````
1626
-
1627
- ### Submitted Data Shape
1628
-
1629
- - **Flat fields** → top-level key/value pairs. If `payloadPath` is set, maps the value to the specified nested path.
1630
- - **GROUP (Visual Section)** → If a group lacks an explicit `name` or `allowMulti`, it is purely visual. Its contents are **flattened** directly onto the target payload layer.
1631
- - **GROUP (Structural Block)** → If a group defines `sectionConfig.name`, `field.name`, or `allowMulti: true`.
1632
- - Its payload is built as a nested object (or an array of objects if `allowMulti`).
1633
- - The object key is determined by priority: `sectionConfig.name` → `field.name` → a generated camelCase derived from `sectionConfig.label` → `__group__`.
1634
- - If a `payloadPath` is provided on the structural block, the payload is mapped to that precise dot-notation path instead of the generated default key.
1635
-
1636
- ```json
1637
- {
1638
- // Flattened visual group fields (no 'name' specified on the group layout)
1639
- "someOtherField": "Flattened value",
1640
-
1641
- // Structural single block nested under derived key
1642
- "basicDetails": {
1643
- "firstName": "John",
1644
- "lastName": "Doe"
1645
- },
1646
-
1647
- // Structural Repeater block (allowMulti: true)
1648
- "experienceList": [
1649
- { "company": "Acme", "position": "Engineer" },
1650
- { "company": "Globex", "position": "Lead" }
1651
- ]
1652
- }
1653
- ```
1654
-
1655
- ---
1656
-
1657
- ## API Authentication (Token)
1658
-
1659
- The Smart Form can attach an auth token to **every library-initiated HTTP call** — this includes:
1660
-
1661
- - Dropdown / Radio / Chip option loading (`optionConfig.apiUrl`, `apiUrls`, `optionUrl`)
1662
- - Dependent dropdown refreshes (cascading selects)
1663
- - Automatic form submission (`submitConfig.apiUrl`)
1664
-
1665
- ### How It Works
1666
-
1667
- The `token` and `tokenHeader` are defined **directly in the configJSON** (`FormSchema`). When the form is parsed, these values are stored in the `SmartFormController` service and automatically applied to every internal HTTP call — no manual `@Input` wiring in the parent template is needed.
1668
-
1669
- ```json
1670
- {
1671
- "entityType": "USER",
1672
- "label": "User Form",
1673
- "formType": "SECTION",
1674
- "token": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
1675
- "tokenHeader": "Authorization",
1676
- "sectionConfig": { "children": [...] }
1677
- }
1678
- ```
1679
-
1680
- > **Note:** `tokenHeader` is optional. When omitted it defaults to `"Authorization"`.
1681
-
1682
- ### Template
1683
-
1684
- No extra bindings are required on `<lib-smart-form>`. The token flows entirely through the JSON:
1685
-
1686
- ```html
1687
- <lib-smart-form
1688
- [formJson]="formJson"
1689
- [labels]="labels"
1690
- (submit)="onSubmit($event)"
1691
- >
1692
- </lib-smart-form>
1693
- ```
1694
-
1695
- ### How the Token Flows Internally
1696
-
1697
- ```
1698
- FormSchema JSON
1699
- │ token / tokenHeader parsed by SmartFormComponent
1700
- ▼
1701
- SmartFormController (token & tokenHeader stored here)
1702
- │ read by every FormFieldComponent directly
1703
- ▼
1704
- HttpHeaders → every API call (dropdowns, submit)
1705
- ```
1706
-
1707
- The token propagates automatically through the entire component tree without any `@Input` prop-drilling.
1708
-
1709
- ### Per-Submit Override
1710
-
1711
- If your submit endpoint requires a **different** token than the option-loading endpoints, set it directly inside `submitConfig`:
1712
-
1713
- ```json
1714
- {
1715
- "submitConfig": {
1716
- "apiUrl": "https://api.example.com/users",
1717
- "method": "POST",
1718
- "token": "ApiKey my-write-only-key",
1719
- "tokenHeader": "X-API-Key"
1720
- }
1721
- }
1722
- ```
1723
-
1724
- `submitConfig.token` always takes precedence over the schema-level `token` for the submit call only.
1725
-
1726
- ### Priority Order
1727
-
1728
- ```
1729
- submitConfig.token → FormSchema.token → (no header sent)
1730
- ```
1731
-
1732
- ---
1733
-
1734
- ## Theme Configuration
1735
-
1736
- The Smart Form exposes a rich set of CSS custom properties (variables) that allow you to fully customise the appearance without touching any component SCSS.
1737
-
1738
- Two built-in themes are provided via a Sass mixin in `smart-form.theme.scss`.
1739
-
1740
- ### Available Themes
1741
-
1742
- | Theme constant | Description |
1743
- | ---------------------------- | ------------------------------------------------ |
1744
- | `$default-smart-form-config` | **Theme 1** — Clean & Professional (light, blue) |
1745
- | `$theme-2-smart-form-config` | **Theme 2** — Vibrant & Modern (dark slate) |
1746
-
1747
- ### Applying a Theme
1748
-
1749
- In your consuming application's component SCSS, `@use` the theme file and call the mixin inside a wrapper class:
1750
-
1751
- ```scss
1752
- @use "commons-shared-web-ui/src/lib/modules/smart-form/smart-form.theme" as sf;
1753
-
1754
- // Default (light) theme
1755
- .my-form-wrapper {
1756
- @include sf.smart-form-theme();
1757
- }
1758
-
1759
- // Dark theme
1760
- .my-form-wrapper.dark {
1761
- @include sf.smart-form-theme(sf.$theme-2-smart-form-config);
1762
- }
1763
- ```
1764
-
1765
- ```html
1766
- <div class="my-form-wrapper" [class.dark]="isDarkTheme">
1767
- <lib-smart-form [formJson]="formJson" (submit)="onSubmit($event)">
1768
- </lib-smart-form>
1769
- </div>
1770
- ```
1771
-
1772
- ### Custom Theme
1773
-
1774
- Pass a partial override map to `smart-form-theme()` to produce a custom theme without affecting the defaults:
1775
-
1776
- ```scss
1777
- @use "commons-shared-web-ui/src/lib/modules/smart-form/smart-form.theme" as sf;
1778
-
1779
- .my-brand-form {
1780
- @include sf.smart-form-theme(
1781
- (
1782
- form-bg: #f4f7ff,
1783
- input-focus-border: #7c3aed,
1784
- input-focus-shadow: 0 0 0 3px rgba(124, 58, 237, 0.2),
1785
- btn-primary-bg: #7c3aed,
1786
- btn-primary-hover-bg: #6d28d9,
1787
- )
1788
- );
1789
- }
1790
- ```
1791
-
1792
- ### CSS Custom Properties Reference
1793
-
1794
- All variables are prefixed `--cc-sf-`. They are generated by the mixin and cascade into every child component automatically.
1795
-
1796
- #### Form Container
1797
-
1798
- | Variable | Default (Theme 1) | Description |
1799
- | ---------------------------- | ---------------------------- | ------------------------------- |
1800
- | `--cc-sf-font-family` | `'Inter', sans-serif` | Font family for the entire form |
1801
- | `--cc-sf-font-size-base` | `0.875rem` | Base font size |
1802
- | `--cc-sf-form-bg` | `#ffffff` | Form wrapper background |
1803
- | `--cc-sf-form-border-radius` | `12px` | Form wrapper border radius |
1804
- | `--cc-sf-form-border` | `none` | Form wrapper border |
1805
- | `--cc-sf-form-shadow` | `0 1px 3px rgba(0,0,0,0.06)` | Form wrapper box shadow |
1806
- | `--cc-sf-form-padding` | `24px` | Form outer padding |
1807
- | `--cc-sf-form-max-width` | `1200px` | Form max width |
1808
- | `--cc-sf-form-title-color` | `#111827` | Form title color |
1809
- | `--cc-sf-form-title-size` | `1.5rem` | Form title font size |
1810
- | `--cc-sf-form-title-weight` | `700` | Form title font weight |
1811
- | `--cc-sf-form-desc-color` | `#6B7280` | Form description color |
1812
- | `--cc-sf-form-desc-size` | `0.875rem` | Form description font size |
1813
-
1814
- #### Section / GROUP Card
1815
-
1816
- | Variable | Default (Theme 1) | Description |
1817
- | ------------------------------ | ------------------- | ----------------------------- |
1818
- | `--cc-sf-section-bg` | `#ffffff` | Section card background |
1819
- | `--cc-sf-section-border` | `1px solid #E5E7EB` | Section card border |
1820
- | `--cc-sf-section-radius` | `10px` | Section card border radius |
1821
- | `--cc-sf-section-shadow` | `0 1px 4px rgba(…)` | Section card box shadow |
1822
- | `--cc-sf-section-padding` | `20px` | Section card inner padding |
1823
- | `--cc-sf-section-gap` | `20px` | Gap between sections |
1824
- | `--cc-sf-section-label-color` | `#1F2937` | Section heading color |
1825
- | `--cc-sf-section-label-size` | `1rem` | Section heading font size |
1826
- | `--cc-sf-section-label-weight` | `600` | Section heading font weight |
1827
- | `--cc-sf-section-label-border` | `2px solid #E5E7EB` | Section heading bottom border |
1828
-
1829
- #### Grid
1830
-
1831
- | Variable | Default (Theme 1) | Description |
1832
- | ------------------ | ----------------- | -------------------------------- |
1833
- | `--cc-sf-grid-gap` | `16px` | Gap between columns in all grids |
1834
-
1835
- #### Labels
1836
-
1837
- | Variable | Default (Theme 1) | Description |
1838
- | ------------------------------ | ----------------- | ----------------------- |
1839
- | `--cc-sf-label-color` | `#111827` | Field label text color |
1840
- | `--cc-sf-label-size` | `0.875rem` | Field label font size |
1841
- | `--cc-sf-label-weight` | `500` | Field label font weight |
1842
- | `--cc-sf-label-required-color` | `#DC2626` | Required asterisk color |
1843
-
1844
- #### Inputs
1845
-
1846
- | Variable | Default (Theme 1) | Description |
1847
- | ------------------------------- | --------------------------------- | ------------------------- |
1848
- | `--cc-sf-input-bg` | `#ffffff` | Input background |
1849
- | `--cc-sf-input-color` | `#111827` | Input text color |
1850
- | `--cc-sf-input-placeholder` | `#9CA3AF` | Placeholder text color |
1851
- | `--cc-sf-input-border` | `1.5px solid #D1D5DB` | Input border |
1852
- | `--cc-sf-input-radius` | `8px` | Input border radius |
1853
- | `--cc-sf-input-padding` | `0.625rem 0.875rem` | Input padding |
1854
- | `--cc-sf-input-shadow` | `none` | Input default box shadow |
1855
- | `--cc-sf-input-hover-border` | `#9CA3AF` | Input border on hover |
1856
- | `--cc-sf-input-focus-border` | `#3B82F6` | Input border when focused |
1857
- | `--cc-sf-input-focus-shadow` | `0 0 0 3px rgba(59,130,246,0.12)` | Focus ring glow |
1858
- | `--cc-sf-input-disabled-bg` | `#F3F4F6` | Disabled input background |
1859
- | `--cc-sf-input-disabled-color` | `#6B7280` | Disabled input text color |
1860
- | `--cc-sf-input-disabled-border` | `#E5E7EB` | Disabled input border |
1861
- | `--cc-sf-input-transition` | `all 0.2s ease` | Input transition speed |
1862
-
1863
- #### Validation
1864
-
1865
- | Variable | Default (Theme 1) | Description |
1866
- | ---------------------------- | ------------------------------- | ------------------------------ |
1867
- | `--cc-sf-error-border` | `#DC2626` | Error state input border color |
1868
- | `--cc-sf-error-bg` | `#FEF2F2` | Error state input background |
1869
- | `--cc-sf-error-focus-shadow` | `0 0 0 3px rgba(220,38,38,0.1)` | Error state focus ring |
1870
- | `--cc-sf-error-text-color` | `#DC2626` | Error message text color |
1871
- | `--cc-sf-error-text-size` | `0.75rem` | Error message font size |
1872
- | `--cc-sf-hint-color` | `#6B7280` | Hint text color |
1873
- | `--cc-sf-hint-size` | `0.75rem` | Hint text font size |
1874
-
1875
- #### Chips
1876
-
1877
- | Variable | Default (Theme 1) | Description |
1878
- | ------------------------------ | ------------------- | ------------------------ |
1879
- | `--cc-sf-chip-bg` | `#ffffff` | Chip default background |
1880
- | `--cc-sf-chip-color` | `#374151` | Chip default text color |
1881
- | `--cc-sf-chip-border` | `1px solid #D1D5DB` | Chip border |
1882
- | `--cc-sf-chip-radius` | `20px` | Chip border radius |
1883
- | `--cc-sf-chip-padding` | `6px 14px` | Chip padding |
1884
- | `--cc-sf-chip-hover-bg` | `#F3F4F6` | Chip hover background |
1885
- | `--cc-sf-chip-selected-bg` | `#3B82F6` | Selected chip background |
1886
- | `--cc-sf-chip-selected-color` | `#ffffff` | Selected chip text |
1887
- | `--cc-sf-chip-selected-border` | `#3B82F6` | Selected chip border |
1888
-
1889
- #### Switch
1890
-
1891
- | Variable | Default (Theme 1) | Description |
1892
- | -------------------------- | ----------------- | ------------------- |
1893
- | `--cc-sf-switch-track-on` | `#3B82F6` | Toggle track (on) |
1894
- | `--cc-sf-switch-track-off` | `#D1D5DB` | Toggle track (off) |
1895
- | `--cc-sf-switch-thumb` | `#ffffff` | Toggle thumb colour |
1896
-
1897
- #### Rating Stars
1898
-
1899
- | Variable | Default (Theme 1) | Description |
1900
- | --------------------- | ----------------- | ------------------ |
1901
- | `--cc-sf-star-filled` | `#F59E0B` | Filled star colour |
1902
- | `--cc-sf-star-empty` | `#D1D5DB` | Empty star colour |
1903
- | `--cc-sf-star-size` | `28px` | Star font size |
1904
-
1905
- #### File Upload Drop Zone
1906
-
1907
- | Variable | Default (Theme 1) | Description |
1908
- | ------------------------------- | ---------------------- | ---------------------------- |
1909
- | `--cc-sf-dropzone-bg` | `#FFFAF1` | Drop zone background |
1910
- | `--cc-sf-dropzone-border` | `1.5px dashed #CBD5E1` | Drop zone border |
1911
- | `--cc-sf-dropzone-radius` | `12px` | Drop zone border radius |
1912
- | `--cc-sf-dropzone-hover-bg` | `#EFF6FF` | Hover background |
1913
- | `--cc-sf-dropzone-hover-border` | `#93C5FD` | Hover border |
1914
- | `--cc-sf-dropzone-over-border` | `#3B82F6` | Active drag-over border |
1915
- | `--cc-sf-dropzone-icon-color` | `#94A3B8` | Cloud icon colour |
1916
- | `--cc-sf-dropzone-link-color` | `#3B82F6` | "click to upload" link color |
1917
- | `--cc-sf-dropzone-hint-color` | `#64748B` | Hint text colour in zone |
1918
- | `--cc-sf-dropzone-over-shadow` | `0 0 0 4px rgba(…)` | Drag-over glow |
1919
-
1920
- #### Stepper
1921
-
1922
- | Variable | Default (Theme 1) | Description |
1923
- | ---------------------------------- | ----------------- | -------------------------------- |
1924
- | `--cc-sf-step-number-size` | `40px` | Step bubble size |
1925
- | `--cc-sf-step-number-bg` | `#E5E7EB` | Idle step bubble background |
1926
- | `--cc-sf-step-number-color` | `#6B7280` | Idle step number colour |
1927
- | `--cc-sf-step-number-font-size` | `0.875rem` | Step number font size |
1928
- | `--cc-sf-step-number-weight` | `600` | Step number font weight |
1929
- | `--cc-sf-step-label-color` | `#6B7280` | Idle step label colour |
1930
- | `--cc-sf-step-label-size` | `0.875rem` | Step label font size |
1931
- | `--cc-sf-step-label-weight` | `500` | Step label font weight |
1932
- | `--cc-sf-step-active-bg` | `#3B82F6` | Active step bubble background |
1933
- | `--cc-sf-step-active-color` | `#ffffff` | Active step number colour |
1934
- | `--cc-sf-step-active-label` | `#1D4ED8` | Active step label colour |
1935
- | `--cc-sf-step-active-label-weight` | `700` | Active step label font weight |
1936
- | `--cc-sf-step-done-bg` | `#22C55E` | Completed step bubble background |
1937
- | `--cc-sf-step-done-color` | `#ffffff` | Completed step number colour |
1938
- | `--cc-sf-step-connector-color` | `#E5E7EB` | Connector line (idle) |
1939
- | `--cc-sf-step-connector-done` | `#22C55E` | Connector line (completed) |
1940
-
1941
- #### Action Buttons
1942
-
1943
- | Variable | Default (Theme 1) | Description |
1944
- | -------------------------------- | -------------------- | ---------------------------------- |
1945
- | `--cc-sf-btn-primary-bg` | `#3B82F6` | Primary (submit) button background |
1946
- | `--cc-sf-btn-primary-color` | `#ffffff` | Primary button text colour |
1947
- | `--cc-sf-btn-primary-radius` | `8px` | Primary button border radius |
1948
- | `--cc-sf-btn-primary-padding` | `0.625rem 1.5rem` | Primary button padding |
1949
- | `--cc-sf-btn-primary-hover-bg` | `#2563EB` | Primary button hover background |
1950
- | `--cc-sf-btn-secondary-bg` | `#F3F4F6` | Secondary (previous) button bg |
1951
- | `--cc-sf-btn-secondary-color` | `#374151` | Secondary button text colour |
1952
- | `--cc-sf-btn-secondary-radius` | `8px` | Secondary button border radius |
1953
- | `--cc-sf-btn-secondary-padding` | `0.625rem 1.5rem` | Secondary button padding |
1954
- | `--cc-sf-btn-secondary-hover-bg` | `#E5E7EB` | Secondary button hover background |
1955
- | `--cc-sf-btn-disabled-opacity` | `0.55` | Disabled button opacity |
1956
- | `--cc-sf-btn-font-size` | `0.875rem` | Button font size |
1957
- | `--cc-sf-btn-font-weight` | `600` | Button font weight |
1958
- | `--cc-sf-btn-transition` | `all 0.2s ease` | Button transition |
1959
- | `--cc-sf-actions-gap` | `12px` | Gap between action buttons |
1960
- | `--cc-sf-actions-padding` | `20px 0 0` | Action bar padding |
1961
- | `--cc-sf-actions-border` | `1px solid #E5E7EB` | Action bar top border |
1962
- | `--cc-sf-btn-add-bg` | `transparent` | Add-instance button background |
1963
- | `--cc-sf-btn-add-color` | `#3B82F6` | Add-instance button text colour |
1964
- | `--cc-sf-btn-add-border` | `1px dashed #CBD5E1` | Add-instance button border |
1965
- | `--cc-sf-btn-add-radius` | `6px` | Add-instance button radius |
1966
- | `--cc-sf-btn-add-hover-bg` | `#EFF6FF` | Add-instance button hover bg |
1967
- | `--cc-sf-btn-add-hover-border` | `#BFDBFE` | Add-instance button hover border |
1968
- | `--cc-sf-btn-remove-bg` | `#FFF5F5` | Remove-instance button background |
1969
- | `--cc-sf-btn-remove-color` | `#E53E3E` | Remove-instance button text colour |
1970
- | `--cc-sf-btn-remove-border` | `1px solid #FED7D7` | Remove-instance button border |
1971
- | `--cc-sf-btn-remove-radius` | `4px` | Remove-instance button radius |
1972
- | `--cc-sf-btn-remove-hover-bg` | `#FED7D7` | Remove-instance button hover bg |
1973
-
1974
- ---
1975
-
1976
- ## Examples
1977
-
1978
- ### Contact Form
1979
-
1980
- {
1981
- "entityType": "CONTACT",
1982
- "label": "Contact Us",
1983
- "formType": "SECTION",
1984
- "submitConfig": {
1985
- "apiUrl": "https://api.example.com/contact",
1986
- "method": "POST",
1987
- "successMessage": "Message sent successfully",
1988
- "errorMessage": "Failed to send message",
1989
- "snackbarConfig": {
1990
- "duration": 6000,
1991
- "verticalPosition": "top",
1992
- "horizontalPosition": "center",
1993
- "showCloseButton": true
1994
- }
1995
- },
1996
- "sectionConfig": {
1997
- "children": [
1998
- {
1999
- "name": "name",
2000
- "label": "Full Name",
2001
- "type": "TEXT_INPUT",
2002
- "subType": "SHORT",
2003
- "required": true
2004
- },
2005
- {
2006
- "name": "email",
2007
- "label": "Email Address",
2008
- "type": "TEXT_INPUT",
2009
- "subType": "EMAIL",
2010
- "required": true
2011
- },
2012
- {
2013
- "name": "message",
2014
- "label": "Message",
2015
- "type": "TEXT_INPUT",
2016
- "subType": "LONG",
2017
- "required": true,
2018
- "textConfig": { "length": { "min": 10, "max": 500 } }
2019
- }
2020
- ]
2021
- }
2022
- }
2023
-
2024
- ````
2025
-
2026
- ### User Registration with Password Validation
2027
-
2028
- ```json
2029
- {
2030
- "entityType": "USER_REGISTRATION",
2031
- "label": "User Registration",
2032
- "formType": "SECTION",
2033
- "sectionConfig": {
2034
- "children": [
2035
- {
2036
- "type": "GROUP",
2037
- "subType": "SECTION",
2038
- "sectionConfig": {
2039
- "label": "Credentials",
2040
- "name": "credentials",
2041
- "children": [
2042
- {
2043
- "type": "ROW",
2044
- "subType": "HORIZONTAL",
2045
- "children": [
2046
- {
2047
- "name": "loginId",
2048
- "label": "Login ID",
2049
- "type": "TEXT_INPUT",
2050
- "subType": "SHORT",
2051
- "required": true,
2052
- "colSpan": 4
2053
- },
2054
- {
2055
- "name": "password",
2056
- "label": "Password",
2057
- "type": "TEXT_INPUT",
2058
- "subType": "PASSWORD",
2059
- "required": true,
2060
- "colSpan": 4
2061
- },
2062
- {
2063
- "name": "confirmPassword",
2064
- "label": "Confirm Password",
2065
- "type": "TEXT_INPUT",
2066
- "subType": "PASSWORD",
2067
- "required": true,
2068
- "colSpan": 4,
2069
- "textConfig": { "matchField": "password" }
2070
- }
2071
- ]
2072
- }
2073
- ]
2074
- }
2075
- }
2076
- ]
2077
- }
2078
- }
2079
- ````
2080
-
2081
- ### Section Stepper with `showOnLastStepOnly`
2082
-
2083
- A three-step registration form using Section Stepper. The **Submit** button carries `"showOnLastStepOnly": true` so it is only visible on the last step. **Previous** and **Next** are rendered automatically by the form — no extra config needed.
2084
-
2085
- ```json
2086
- {
2087
- "entityType": "REGISTRATION",
2088
- "label": "Event Registration",
2089
- "formType": "SECTION",
2090
- "sectionStepper": true,
2091
- "submitConfig": {
2092
- "apiUrl": "https://api.example.com/registrations",
2093
- "method": "POST",
2094
- "successMessage": "Registration submitted successfully!",
2095
- "redirectUrl": "/dashboard"
2096
- },
2097
- "actionBarConfig": {
2098
- "buttons": [
2099
- {
2100
- "id": "cancel",
2101
- "label": "Cancel",
2102
- "variant": "outline",
2103
- "alignment": "left",
2104
- "order": 0,
2105
- "action": { "kind": "navigate", "redirectUrl": "/dashboard" }
2106
- },
2107
- {
2108
- "id": "save-draft",
2109
- "label": "Save as Draft",
2110
- "variant": "secondary",
2111
- "alignment": "right",
2112
- "order": 0,
2113
- "action": { "kind": "draft", "extraPayload": { "status": "DRAFT" } }
2114
- },
2115
- {
2116
- "id": "submit",
2117
- "label": "Submit",
2118
- "variant": "primary",
2119
- "alignment": "right",
2120
- "order": 1,
2121
- "showOnLastStepOnly": true,
2122
- "action": { "kind": "submit" }
2123
- }
2124
- ]
2125
- },
2126
- "sectionConfig": {
2127
- "children": [
2128
- {
2129
- "type": "GROUP",
2130
- "subType": "SECTION",
2131
- "sectionConfig": {
2132
- "label": "Personal Info",
2133
- "children": [
2134
- {
2135
- "type": "ROW",
2136
- "subType": "HORIZONTAL",
2137
- "children": [
2138
- {
2139
- "name": "firstName",
2140
- "label": "First Name",
2141
- "type": "TEXT_INPUT",
2142
- "subType": "SHORT",
2143
- "required": true,
2144
- "colSpan": 6
2145
- },
2146
- {
2147
- "name": "lastName",
2148
- "label": "Last Name",
2149
- "type": "TEXT_INPUT",
2150
- "subType": "SHORT",
2151
- "required": true,
2152
- "colSpan": 6
2153
- }
2154
- ]
2155
- },
2156
- {
2157
- "name": "email",
2158
- "label": "Email Address",
2159
- "type": "TEXT_INPUT",
2160
- "subType": "EMAIL",
2161
- "required": true
2162
- }
2163
- ]
2164
- }
2165
- },
2166
- {
2167
- "type": "GROUP",
2168
- "subType": "SECTION",
2169
- "sectionConfig": {
2170
- "label": "Event Preferences",
2171
- "children": [
2172
- {
2173
- "name": "session",
2174
- "label": "Preferred Session",
2175
- "type": "DROPDOWN",
2176
- "subType": "SINGLE",
2177
- "required": true,
2178
- "optionConfig": {
2179
- "optionList": [
2180
- { "label": "Morning", "code": "MORNING" },
2181
- { "label": "Afternoon", "code": "AFTERNOON" },
2182
- { "label": "Evening", "code": "EVENING" }
2183
- ]
2184
- }
2185
- },
2186
- {
2187
- "name": "dietaryRequirements",
2188
- "label": "Dietary Requirements",
2189
- "type": "CHIP",
2190
- "subType": "MULTIPLE",
2191
- "optionConfig": {
2192
- "optionList": [
2193
- { "label": "Vegetarian", "code": "VEG" },
2194
- { "label": "Vegan", "code": "VEGAN" },
2195
- { "label": "Gluten-Free", "code": "GF" },
2196
- { "label": "None", "code": "NONE" }
2197
- ]
2198
- }
2199
- }
2200
- ]
2201
- }
2202
- },
2203
- {
2204
- "type": "GROUP",
2205
- "subType": "SECTION",
2206
- "sectionConfig": {
2207
- "label": "Review & Submit",
2208
- "children": [
2209
- {
2210
- "name": "agreeToTerms",
2211
- "label": "I agree to the terms and conditions",
2212
- "type": "CHECKBOX",
2213
- "subType": "BOOL",
2214
- "required": true
2215
- },
2216
- {
2217
- "name": "notes",
2218
- "label": "Additional Notes",
2219
- "type": "TEXT_INPUT",
2220
- "subType": "LONG"
2221
- }
2222
- ]
2223
- }
2224
- }
2225
- ]
2226
- }
2227
- }
2228
- ```
2229
-
2230
- **What the action bar looks like on each step:**
2231
-
2232
- | Step | Left side | Right side |
2233
- |------|-----------|------------|
2234
- | Step 1 (first) | Cancel | Save as Draft · **Next** |
2235
- | Step 2 | Cancel · **Previous** | Save as Draft · **Next** |
2236
- | Step 3 (last) | Cancel · **Previous** | Save as Draft · **Submit** |
2237
-
2238
- - **Previous** / **Next** are rendered automatically; no button config needed.
2239
- - **Submit** (`showOnLastStepOnly: true`) is hidden on steps 1 and 2, then replaces **Next** on step 3.
2240
- - **Cancel** and **Save as Draft** have no `showOnLastStepOnly` flag, so they appear on every step.
2241
-
2242
- ### Repeatable Work Experience
2243
-
2244
- ```json
2245
- {
2246
- "type": "GROUP",
2247
- "subType": "SECTION",
2248
- "sectionConfig": {
2249
- "label": "Work Experience",
2250
- "allowMulti": true,
2251
- "name": "experienceList",
2252
- "children": [
2253
- {
2254
- "name": "company",
2255
- "label": "Company",
2256
- "type": "TEXT_INPUT",
2257
- "subType": "SHORT",
2258
- "required": true
2259
- },
2260
- {
2261
- "name": "position",
2262
- "label": "Position",
2263
- "type": "TEXT_INPUT",
2264
- "subType": "SHORT",
2265
- "required": true
2266
- },
2267
- {
2268
- "type": "ROW",
2269
- "subType": "HORIZONTAL",
2270
- "children": [
2271
- {
2272
- "name": "startDate",
2273
- "label": "Start Date",
2274
- "type": "DATE",
2275
- "subType": "SINGLE",
2276
- "required": true,
2277
- "colSpan": 6
2278
- },
2279
- {
2280
- "name": "endDate",
2281
- "label": "End Date",
2282
- "type": "DATE",
2283
- "subType": "SINGLE",
2284
- "colSpan": 6
2285
- }
2286
- ]
2287
- }
2288
- ]
2289
- }
2290
- }
2291
- ```
2292
-
2293
- ---
2294
-
2295
- ## API Reference
2296
-
2297
- ### Component Inputs
2298
-
2299
- | Input | Type | Required | Description |
2300
- | --------------------- | ------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------- |
2301
- | `formJson` | string | Yes | JSON string of the form schema configuration |
2302
- | `mode` | string | No | Determines whether the form creates or edits an entity: `"CREATE" \| "EDIT"` (default: `"CREATE"`) |
2303
- | `initialValues` | object | No | Pre-populate form values (key = field `name`) |
2304
- | `enableDraftAutoSave` | boolean | No | Enable auto-save drafts (default: `false`) |
2305
- | `labels` | object | No | Flat i18n key–value map. Keys must match the string values used in the JSON schema. See [i18n section](#i18n--translation-support). |
2306
- | `readOnly` | boolean | No | When `true`, all form controls are disabled and the action bar is hidden. Use this for **read-only preview** in a Form Builder wizard (default: `false`). |
2307
-
2308
-
2309
- ### Component Outputs
2310
-
2311
- | `submit` | `EventEmitter<object>` | Emitted when the form is submitted. Contains collected form data or the API response |
2312
- | `draftSave` | `EventEmitter<string>` | Emitted when a draft is saved (requires `enableDraftAutoSave: true`) |
2313
- | `fileAdded` | `EventEmitter<any>` | Emitted when a file upload starts internally (MEDIA_UPLOAD or FILE_UPLOAD). |
2314
- | `fileRemoved` | `EventEmitter<any>` | Emitted when a file upload completes, fails, or is manually removed. |
2315
- | `suffixActionClick` | `EventEmitter<{ fieldName: string; actionId: string }>` | Emitted when a clickable action icon (configured via `suffixActionIcons`) is clicked inside a text or number field. |
2316
-
2317
- ### Usage in Component
2318
-
2319
- ```typescript
2320
- @Component({
2321
- template: `
2322
- <lib-smart-form
2323
- [formJson]="formJson"
2324
- [initialValues]="initialData"
2325
- [labels]="labels"
2326
- (submit)="handleSubmit($event)"
2327
- >
2328
- </lib-smart-form>
2329
- `,
2330
- })
2331
- export class MyComponent {
2332
- formJson: string; // JSON.stringify(yourSchemaObject)
2333
- initialData = { firstName: "John" };
2334
- labels = { "FIELD.FIRST_NAME": "First Name" };
2335
-
2336
- handleSubmit(data: any) {
2337
- console.log("Form Data:", data);
2338
- }
2339
- }
2340
- ```
2341
-
2342
- ---
2343
-
2344
- ## Best Practices
2345
-
2346
- 1. Use **meaningful camelCase field names** (`firstName`, `emailId`).
2347
- 2. Store all label strings in your **i18n JSON files** and pass them via `[labels]`. Every label property in the JSON schema should be an i18n key that exists in your translation files. These are processed by `SmartFormTranslationUtils` before rendering.
2348
- 3. Always set `name` on `GROUP` + `allowMulti` sections — it becomes the `FormArray` key.
2349
- 4. Use `colSpan` to build responsive multi-column layouts inside `ROW`.
2350
- 5. Use `visibilityExpression` to keep forms concise — hidden fields are excluded from submission.
2351
- 6. Provide `hints` and `placeholders` for complex fields; these are also translatable.
2352
- 7. Use `matchField` for confirm-password style validation instead of custom validators.
2353
- 8. Test `GENERATED` formulas with `null`/`undefined` inputs — they will be called before the user types.
2354
- 9. For long forms, prefer `STEPPER` over a single `SECTION` with many fields.
2355
- 10. Verify `submitConfig.apiUrl` CORS settings before relying on automatic API submission.
2356
- 11. Always set **`token`** in the configJSON (`FormSchema.token`) when dropdowns load from secured API endpoints — without it the requests will be unauthenticated. The token flows automatically to every field; no `@Input` binding is needed on `<lib-smart-form>`.
2357
- 12. Apply themes using the `smart-form-theme()` mixin inside a scoped wrapper class, not at `:root` level, to avoid conflicts with other form instances on the same page.
2358
-
2359
- ---
2360
-
2361
- ## Troubleshooting
2362
-
2363
- ### Form not rendering
2364
-
2365
- - Ensure `formJson` is a valid JSON **string** (use `JSON.stringify`).
2366
- - Check the browser console for parse errors.
2367
-
2368
- ### Labels not translating
2369
-
2370
- - Confirm the key in `labels` exactly matches the string value in the schema JSON.
2371
- - If `labels` arrives after `formJson`, the component automatically re-parses — but make sure `ngOnChanges` is reaching the component (i.e., `labels` is a fresh object reference, not mutated in place).
2372
-
2373
- ### Repeater instances sharing values
2374
-
2375
- - Ensure `sectionConfig.name` is set on the `GROUP` field — without it the `FormArray` key defaults to `__repeater__` and may conflict.
2376
- - Each repeater instance starts blank by design (`inRepeater: true` disables cross-instance controller reads).
2377
-
2378
- ### Generated fields not updating
2379
-
2380
- - Verify `variables` lists every field name the formula reads.
2381
- - Check formula syntax — it must be a valid **named** JavaScript function.
2382
-
2383
- ### API submission not working
2384
-
2385
- - Verify `submitConfig.apiUrl` is correct and the server allows the HTTP method.
2386
- - Check CORS settings on the API endpoint.
2387
-
2388
- ### Dropdown options not loading
2389
-
2390
- - Verify `apiUrl` / `optionUrl` is reachable.
2391
- - Check `dataPath` if the response wraps the array in an object.
2392
- - Verify `labelPath` and `valuePath` exist on each item.
2393
- - For dependent dropdowns, ensure the parent field name in `dependencies` maps matches the field's `name` exactly.
2394
-
2395
- ### Dropdown options return 401 / 403
2396
-
2397
- - Set `token` and optionally `tokenHeader` inside the **configJSON** (`FormSchema`) so the library attaches auth headers to every dropdown API call automatically.
2398
- - If only the **submit** endpoint is secured, set `token` inside `submitConfig` in the JSON schema — it takes precedence over `FormSchema.token` for the submit call only.
2399
- - Confirm the token value includes the scheme prefix if required by your API (e.g. `"Bearer "` not just the raw JWT).
2400
-
2401
- ---
2402
-
2403
- ## License
2404
-
2405
- This module is part of the shared-ui library.