1
+ ![ Image] ( ./ngx-dynamic-form-factory.png )
2
+
3
+ ## 📚 Table of Contents
4
+
5
+ - [ ✅ Key Features] ( #-key-features )
6
+ - [ 📦 Installation] ( #-installation )
7
+ - [ 📌 Example Usage] ( #-example-usage )
8
+ - [ 🚀 Usage] ( #-usage )
9
+ - [ 1️⃣ Add Styles to ` angular.json ` ] ( #1️⃣-add-styles-to-angularjson )
10
+ - [ 2️⃣ Basic Example of Usage] ( #2️⃣-basic-example-of-usage )
11
+ - [ 🌐 Using Aliases for Server-Provided JSON Configuration] ( #-using-aliases-for-server-provided-json-configuration )
12
+ - [ 🔹 Example] ( #-example )
13
+ - [ 🛠 Registering Aliases in ` app.config.ts ` ] ( #-registering-aliases-in-appconfigts )
14
+ - [ 📄 Defining Form Fields in an External File] ( #-defining-form-fields-in-an-external-file )
15
+ - [ 🛠 Built-in Example Fields & Custom Component Support] ( #-built-in-example-fields--custom-component-support )
16
+ - [ 📌 Field Types and Examples] ( #-field-types-and-examples )
17
+ - [ 🔹 Example Usage of Each Field Type] ( #-example-usage-of-each-field-type )
18
+ - [ 📌 InputField] ( #-inputfield )
19
+ - [ 📌 SelectField] ( #-selectfield )
20
+ - [ 📌 UIElement] ( #-uielement )
21
+ - [ 📌 FieldGroup] ( #-fieldgroup )
22
+ - [ 📌 GenericField] ( #-genericfield )
23
+
1
24
## ✅ Key Features
2
25
3
26
- 🔹 ** Dynamic Form Rendering** – Generate Angular forms dynamically from JSON configuration.
@@ -21,6 +44,12 @@ To install **ngx-dynamic-forms-factory**, run the following command in your Angu
21
44
npm install ngx-dynamic-forms-factory
22
45
```
23
46
47
+ ## 📌 Example Usage
48
+
49
+ For a complete example of how to use ** ngx-dynamic-forms-factory** in a real-world scenario, check out the example project:
50
+
51
+ 🔗 ** [ Example Usage] ( https://github.com/martinstefanovic/angular-dynamic-forms/tree/master/projects/examples/src/app ) **
52
+
24
53
## 🚀 Usage
25
54
26
55
### 1️⃣ Add Styles to ` angular.json `
@@ -124,7 +153,7 @@ To keep the form configuration modular and reusable, define the form fields in a
124
153
125
154
Create a file named ` json-form-example.ts ` and add the following:
126
155
127
- ```` typescript
156
+ ``` typescript
128
157
import { Validators } from ' @angular/forms' ;
129
158
import { createField , InputField } from ' ngx-dynamic-forms-factory' ;
130
159
@@ -143,73 +172,80 @@ export default [
143
172
},
144
173
}),
145
174
];
175
+ ```
146
176
147
177
## 🛠 Built-in Example Fields & Custom Component Support
148
178
149
179
This library provides ** two example field components** intended for ** testing and demonstration purposes** .
150
180
151
181
If you want to ** add your own custom components** , you can check out the example implementation here:
152
- 🔗 ** [Custom Components Guide ](https :// github.com/martinstefanovic/angular-dynamic-forms/tree/master/projects/examples/src/app/components)**
182
+ 🔗 ** [ Custom Components Example ] ( https://github.com/martinstefanovic/angular-dynamic-forms/tree/master/projects/examples/src/app/components/input-password ) **
153
183
154
184
This guide explains how to create and register ** custom form components** to extend the functionality of ` ngx-dynamic-forms-factory ` .
155
185
156
-
157
186
## 📌 Field Types and Examples
158
187
159
188
The ` createField ` function is used to create form fields based on different interfaces. Below is a table of available field types and their descriptions.
160
189
161
- | ** Interface** | ** Description** |
162
- |------------------| ----------------|
163
- | ** `InputField`** | EXAMPLE FIELD! Standard text input field with validation and placeholder. |
164
- | ** `SelectField`** | EXAMPLE FIELD! Dropdown select field with predefined options. |
165
- | ** `UIElement`** | Used to insert a custom UI component into the form. |
166
- | ** `FieldGroup`** | Groups multiple fields together in a single column in the grid layout. |
167
- | ** `GenericField`** | Base interface for extending and creating custom fields. |
190
+ | ** Interface** | ** Description** |
191
+ | ------------------ | ------------------------------------------------------------------------- |
192
+ | ** ` InputField ` ** | EXAMPLE FIELD! Standard text input field with validation and placeholder. |
193
+ | ** ` SelectField ` ** | EXAMPLE FIELD! Dropdown select field with predefined options. |
194
+ | ** ` UIElement ` ** | Used to insert a custom UI component into the form. |
195
+ | ** ` FieldGroup ` ** | Groups multiple fields together in a single column in the grid layout. |
196
+ | ** ` GenericField ` ** | Base interface for extending and creating custom fields. |
168
197
169
198
---
170
199
171
200
### ** 🔹 Example Usage of Each Field Type**
172
201
173
202
#### ** 📌 InputField**
203
+
174
204
``` typescript
175
205
import { Validators } from ' @angular/forms' ;
176
206
import { createField , InputField } from ' ngx-dynamic-forms-factory' ;
177
207
178
- createField <InputField >({
179
- colSize: ' ui-col-span-12 sm:ui-col-span-4' ,
180
- controlType: InputField ,
181
- label: ' Name' ,
182
- placeholder: ' Enter name' ,
183
- type: ' text' ,
184
- options: {
185
- formControlName: ' name' ,
186
- value: ' ' ,
187
- validators: [Validators .required , Validators .minLength (3 )],
188
- },
189
- });
190
- ` ` ` `
208
+ [
209
+ createField <InputField >({
210
+ colSize: ' ui-col-span-12 sm:ui-col-span-4' ,
211
+ controlType: InputField ,
212
+ label: ' Name' ,
213
+ placeholder: ' Enter name' ,
214
+ type: ' text' ,
215
+ options: {
216
+ formControlName: ' name' ,
217
+ value: ' ' ,
218
+ validators: [Validators .required , Validators .minLength (3 )],
219
+ },
220
+ });
221
+ ... // Other fields
222
+ ]
223
+ ```
191
224
192
225
#### ** 📌 SelectField**
193
226
194
227
``` typescript
195
228
import { createField , SelectField } from ' ngx-dynamic-forms-factory' ;
196
229
197
- createField<SelectField>({
198
- colSize: 'ui-col-span-12 sm:ui-col-span-4',
199
- controlType: SelectField,
200
- label: 'Country',
201
- selectOptions: [
202
- { id: 'us', name: 'United States' },
203
- { id: 'ca', name: 'Canada' },
204
- ],
205
- selectValue: 'id',
206
- selectLabel: 'name',
207
- options: {
208
- formControlName: 'country',
209
- value: '',
210
- validators: [],
211
- },
212
- });
230
+ [
231
+ createField <SelectField >({
232
+ colSize: ' ui-col-span-12 sm:ui-col-span-4' ,
233
+ controlType: SelectField ,
234
+ label: ' Country' ,
235
+ selectOptions: [
236
+ { id: ' us' , name: ' United States' },
237
+ { id: ' ca' , name: ' Canada' },
238
+ ],
239
+ selectValue: ' id' ,
240
+ selectLabel: ' name' ,
241
+ options: {
242
+ formControlName: ' country' ,
243
+ value: ' ' ,
244
+ validators: [],
245
+ },
246
+ });
247
+ ... // Other fields
248
+ ]
213
249
```
214
250
215
251
#### ** 📌 UIElement**
@@ -218,36 +254,42 @@ createField<SelectField>({
218
254
import { createField , UIElement } from ' ngx-dynamic-forms-factory' ;
219
255
import { CustomTitleComponent } from ' ./custom-title.component' ;
220
256
221
- createField<UIElement>({
222
- colSize: 'ui-col-span-12',
223
- controlType: CustomTitleComponent,
224
- data: { title: 'Personal Information' },
225
- });
257
+ [
258
+ createField <UIElement >({
259
+ colSize: ' ui-col-span-12' ,
260
+ controlType: CustomTitleComponent ,
261
+ data: { title: ' Personal Information' },
262
+ })
263
+ ... // Other fields
264
+ ]
226
265
```
227
266
228
267
#### ** 📌 FieldGroup**
229
268
230
269
``` typescript
231
270
import { createField , FieldGroup , InputField } from ' ngx-dynamic-forms-factory' ;
232
271
233
- createField<FieldGroup>({
234
- colSize: 'ui-col-span-12 sm:ui-col-span-4',
235
- group: [
236
- createField<InputField>({
237
- colSize: 'ui-col-span-12',
238
- controlType: InputField,
239
- label: 'Email',
240
- placeholder: 'example@email.com',
241
- type: 'email',
242
- options: {
243
- formControlName: 'email',
244
- value: '',
245
- validators: [Validators.email, Validators.required],
246
- },
247
- }),
272
+ [
273
+ createField <FieldGroup >({
274
+ colSize: ' ui-col-span-12 sm:ui-col-span-4' ,
275
+ group: [
276
+ createField <InputField >({
277
+ colSize: ' ui-col-span-12' ,
278
+ controlType: InputField ,
279
+ label: ' Email' ,
280
+ placeholder: ' example@email.com' ,
281
+ type: ' email' ,
282
+ options: {
283
+ formControlName: ' email' ,
284
+ value: ' ' ,
285
+ validators: [Validators .email , Validators .required ],
286
+ },
287
+ }),
288
+ ... // Other fields
289
+ ],
290
+ })
248
291
... // Other fields
249
- ],
250
- });
292
+ ]
251
293
```
252
294
253
295
#### ** 📌 GenericField**
0 commit comments