You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 4, 2017. It is now read-only.
Copy file name to clipboardExpand all lines: public/docs/ts/latest/cookbook/dynamic-form.jade
+82-71Lines changed: 82 additions & 71 deletions
Original file line number
Diff line number
Diff line change
@@ -1,109 +1,115 @@
1
1
include../_util-fns
2
2
3
3
:marked
4
-
We can't always justify the cost and time to build handcrafted forms,
5
-
especially if we'll need a great number of them, they're similar to each other, and they change frequently
4
+
Building handcrafted forms can be costly and time-consuming,
5
+
especially if you need a great number of them, they're similar to each other, and they change frequently
6
6
to meet rapidly changing business and regulatory requirements.
7
-
8
-
It may be more economical to create the forms dynamically, based on metadata that describe the business object model.
9
-
10
-
In this cookbook we show how to use `formGroup` to dynamically render a simple form with different control types and validation.
11
-
It's a primitive start.
7
+
8
+
It may be more economical to create the forms dynamically, based on
9
+
metadata that describes the business object model.
10
+
11
+
This cookbook shows you how to use `formGroup` to dynamically
12
+
render a simple form with different control types and validation.
13
+
It's a primitive start.
12
14
It might evolve to support a much richer variety of questions, more graceful rendering, and superior user experience.
13
15
All such greatness has humble beginnings.
14
-
15
-
In our example we use a dynamic form to build an online application experience for heroes seeking employment.
16
+
17
+
The example in this cookbook is a dynamic form to build an
18
+
online application experience for heroes seeking employment.
16
19
The agency is constantly tinkering with the application process.
17
-
We can create the forms on the fly *without changing our application code*.
18
-
20
+
You can create the forms on the fly *without changing the application code*.
21
+
19
22
<aid="toc"></a>
20
23
:marked
21
-
## Table of contents
22
-
23
-
[Bootstrap](#bootstrap)
24
-
25
-
[Question Model](#object-model)
26
-
27
-
[Form Component](#form-component)
28
-
29
-
[Questionnaire Metadata](#questionnaire-metadata)
30
-
31
-
[Dynamic Template](#dynamic-template)
24
+
# Contents
25
+
* [Bootstrap](#bootstrap)
26
+
* [Question model](#object-model)
27
+
* [Question form components](#form-component)
28
+
* [Questionnaire data](#questionnaire-data)
29
+
* [Dynamic template](#dynamic-template)
32
30
33
31
:marked
34
-
**See the <live-example name="cb-dynamic-form"></live-example>**.
32
+
See the <live-example name="cb-dynamic-form"></live-example>.
35
33
36
34
.l-main-section
37
35
<aid="bootstrap"></a>
38
36
:marked
39
37
## Bootstrap
40
38
41
-
We start by creating an `NgModule` called `AppModule`.
39
+
Start by creating an `NgModule` called `AppModule`.
42
40
43
-
In our example we will be using Reactive Forms.
44
-
45
-
Reactive Forms belongs to a different `NgModule` called `ReactiveFormsModule`, so in order to access any Reactive Forms directives, we have to import `ReactiveFormsModule` from the `@angular/forms` library.
41
+
This cookbook uses [reactive forms](../guide/reactive-forms.html).
46
42
47
-
We bootstrap our `AppModule` in main.ts.
43
+
Reactive forms belongs to a different `NgModule` called `ReactiveFormsModule`,
44
+
so in order to access any reactive forms directives, you have to import
45
+
`ReactiveFormsModule` from the `@angular/forms` library.
46
+
47
+
Bootstrap the `AppModule` in `main.ts`.
48
48
49
49
+makeTabs(
50
50
`cb-dynamic-form/ts/src/app/app.module.ts,
51
51
cb-dynamic-form/ts/src/main.ts`,
52
52
null,
53
53
`app.module.ts,
54
54
main.ts`
55
-
)
55
+
)
56
56
57
57
.l-main-section
58
58
<aid="object-model"></a>
59
59
:marked
60
-
## Question Model
60
+
## Question model
61
61
62
62
The next step is to define an object model that can describe all scenarios needed by the form functionality.
63
-
The hero application process involves a form with a lot of questions.
64
-
The "question" is the most fundamental object in the model.
63
+
The hero application process involves a form with a lot of questions.
64
+
The _question_ is the most fundamental object in the model.
65
65
66
-
We have created `QuestionBase` as the most fundamental question class.
66
+
The following `QuestionBase` is a fundamental question class.
Notice this component can present any type of question in our model.
117
-
We only have two types of questions at this point but we can imagine many more.
122
+
Notice this component can present any type of question in your model.
123
+
You only have two types of questions at this point but you can imagine many more.
118
124
The `ngSwitch` determines which type of question to display.
119
-
120
-
In both components we're relying on Angular's **formGroup** to connect the template HTML to the
125
+
126
+
In both components you're relying on Angular's **formGroup** to connect the template HTML to the
121
127
underlying control objects, populated from the question model with display and validation rules.
122
128
123
-
`formControlName` and `formGroup` are directives defined in `ReactiveFormsModule`. Our templates can access these directives directly since we imported `ReactiveFormsModule` from `AppModule`.
129
+
`formControlName` and `formGroup` are directives defined in
130
+
`ReactiveFormsModule`. The templates can access these directives
131
+
directly since you imported `ReactiveFormsModule` from `AppModule`.
124
132
125
-
<aid="questionnaire-metadata"></a>
133
+
<aid="questionnaire-data"></a>
126
134
:marked
127
135
## Questionnaire data
128
136
:marked
129
-
`DynamicFormComponent` expects the list of questions in the form of an array bound to `@Input() questions`.
137
+
`DynamicFormComponent` expects the list of questions in the form of an array bound to `@Input() questions`.
138
+
139
+
The set of questions you've defined for the job application is returned from the `QuestionService`.
140
+
In a real app you'd retrieve these questions from storage.
141
+
142
+
The key point is that you control the hero job application questions
143
+
entirely through the objects returned from `QuestionService`.
144
+
Questionnaire maintenance is a simple matter of adding, updating,
145
+
and removing objects from the `questions` array.
130
146
131
-
The set of questions we have defined for the job application is returned from the `QuestionService`.
132
-
In a real app we'd retrieve these questions from storage.
133
-
134
-
The key point is that we control the hero job application questions entirely through the objects returned from `QuestionService`.
135
-
Questionnaire maintenance is a simple matter of adding, updating, and removing objects from the `questions` array.
0 commit comments