platformcommons-web-lib 1.0.0

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