Skip to content

Commit d94cbe3

Browse files
committed
DOC
1 parent 8987749 commit d94cbe3

File tree

4 files changed

+106
-62
lines changed

4 files changed

+106
-62
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
![Image](./projects/ngx-dynamic-forms//ngx-dynamic-form-factory.png)
2+
13
## 📚 Table of Contents
24

35
- [✅ Key Features](#-key-features)

projects/examples/src/app/json-form-example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export default [
8383
controlType: DynamicInputComponent,
8484
label: 'Phone',
8585
options: {
86-
formControlName: 'nickname',
86+
formControlName: 'phone',
8787
value: '',
8888
validators: [Validators.minLength(3), Validators.pattern(/[0-9]/), Validators.required],
8989
},

projects/ngx-dynamic-forms/README.md

Lines changed: 103 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
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+
124
## ✅ Key Features
225

326
- 🔹 **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
2144
npm install ngx-dynamic-forms-factory
2245
```
2346

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+
2453
## 🚀 Usage
2554

2655
### 1️⃣ Add Styles to `angular.json`
@@ -124,7 +153,7 @@ To keep the form configuration modular and reusable, define the form fields in a
124153

125154
Create a file named `json-form-example.ts` and add the following:
126155

127-
````typescript
156+
```typescript
128157
import { Validators } from '@angular/forms';
129158
import { createField, InputField } from 'ngx-dynamic-forms-factory';
130159

@@ -143,73 +172,80 @@ export default [
143172
},
144173
}),
145174
];
175+
```
146176

147177
## 🛠 Built-in Example Fields & Custom Component Support
148178

149179
This library provides **two example field components** intended for **testing and demonstration purposes**.
150180

151181
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)**
153183

154184
This guide explains how to create and register **custom form components** to extend the functionality of `ngx-dynamic-forms-factory`.
155185

156-
157186
## 📌 Field Types and Examples
158187

159188
The `createField` function is used to create form fields based on different interfaces. Below is a table of available field types and their descriptions.
160189

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. |
168197

169198
---
170199

171200
### **🔹 Example Usage of Each Field Type**
172201

173202
#### **📌 InputField**
203+
174204
```typescript
175205
import { Validators } from '@angular/forms';
176206
import { createField, InputField } from 'ngx-dynamic-forms-factory';
177207

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+
```
191224

192225
#### **📌 SelectField**
193226

194227
```typescript
195228
import { createField, SelectField } from 'ngx-dynamic-forms-factory';
196229

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+
]
213249
```
214250

215251
#### **📌 UIElement**
@@ -218,36 +254,42 @@ createField<SelectField>({
218254
import { createField, UIElement } from 'ngx-dynamic-forms-factory';
219255
import { CustomTitleComponent } from './custom-title.component';
220256

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+
]
226265
```
227266

228267
#### **📌 FieldGroup**
229268

230269
```typescript
231270
import { createField, FieldGroup, InputField } from 'ngx-dynamic-forms-factory';
232271

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+
})
248291
... // Other fields
249-
],
250-
});
292+
]
251293
```
252294

253295
#### **📌 GenericField**
155 KB
Loading

0 commit comments

Comments
 (0)