Skip to content

Commit 6ea4ee9

Browse files
committed
md
1 parent 8cf6380 commit 6ea4ee9

File tree

2 files changed

+60
-46
lines changed

2 files changed

+60
-46
lines changed

README.md

Lines changed: 59 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,61 @@
11
# Dynamic Form with template-driven
22

3-
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.3.2.
4-
5-
## Development server
6-
7-
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
8-
9-
## Code scaffolding
10-
11-
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
12-
13-
## Build
14-
15-
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build.
16-
17-
## Running unit tests
18-
19-
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
20-
21-
## Running end-to-end tests
22-
23-
Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
24-
Before running the tests make sure you are serving the app via `ng serve`.
25-
26-
## Further help
27-
28-
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
3+
## Logic
4+
This dynamic form use template driven form And Very simple to use
5+
1. *ngFor the form array
6+
1. provide the style stack with the current form info and parent Form
7+
1. provide the model for show error component inside style stack
8+
9+
10+
## Usage
11+
12+
**inside component.ts**
13+
```javascript
14+
constructor(private title: Title) {
15+
title.setTitle('Login');
16+
17+
const usernameForm: BaseForm = new BaseForm('Username', 'Username', 'username', 'text');
18+
usernameForm.rules = {
19+
'required': true,
20+
'minlength': 5,
21+
'maxlength': 7,
22+
'pattern': '[\\w]*',
23+
'patternInfo': 'Only word and number no spaces and symbols'
24+
};
25+
usernameForm.value = 'myName';
26+
27+
const passwordForm: BaseForm = new BaseForm('Password', 'Password', 'password', 'password');
28+
passwordForm.rules = {
29+
'required': true,
30+
'maxlength': 10
31+
};
32+
this.baseForms.push(usernameForm, passwordForm);
33+
34+
}
35+
36+
```
37+
38+
1. app.module.ts
39+
1. include components in declarations
40+
1. show-errors.component
41+
1. style-stack.component
42+
1. Create BaseForm Object from src/app/forms/base-form.ts
43+
1. Supply constructor in login.component.ts with label,placeholder,name, input type, like pages/login/login.component.ts
44+
1. Supply rules if needed
45+
1. push in array
46+
1. in html usage like pages/login/login.component.html
47+
48+
## Rules
49+
* required : true | false
50+
* minlength: number
51+
* maxlength: number
52+
* pattern : regex
53+
* patternInfo: String the info of regex rule
54+
55+
## Default value
56+
* in BaseForm Object set the .value, it will be 2 way binding
57+
58+
## required file
59+
* all inside src/app/forms
60+
* optional the src/style.css for form animation
61+
* bootstrap v4 for this demo

src/app/pages/login/login.component.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,7 @@ import {BaseForm} from '../../forms/base-form';
1010
export class LoginComponent implements OnInit {
1111

1212
public baseForms: BaseForm[] = [];
13-
constructor(private title: Title) {
14-
title.setTitle('Login');
15-
16-
const usernameForm: BaseForm = new BaseForm('Username', 'Username', 'username', 'text');
17-
usernameForm.rules = {
18-
'required': true,
19-
'minlength': 5,
20-
'maxlength': 7,
21-
'pattern': '[\\w]*',
22-
'patternInfo': 'Only word and number no spaces and symbols'
23-
};
24-
usernameForm.value = 'myName';
25-
const passwordForm: BaseForm = new BaseForm('Password', 'Password', 'password', 'password');
26-
passwordForm.rules = {
27-
'required': true,
28-
'maxlength': 10
29-
};
30-
this.baseForms.push(usernameForm, passwordForm);
31-
32-
}
13+
c
3314

3415
ngOnInit() {
3516
}

0 commit comments

Comments
 (0)