Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 6a9007c

Browse files
kapunahelewongwardbell
authored andcommitted
docs(dynamic-forms): edit copy to guidelines standards (#3525)
1 parent 0cf9832 commit 6a9007c

File tree

1 file changed

+82
-71
lines changed

1 file changed

+82
-71
lines changed

public/docs/ts/latest/cookbook/dynamic-form.jade

Lines changed: 82 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,115 @@
11
include ../_util-fns
22

33
: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
66
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.
1214
It might evolve to support a much richer variety of questions, more graceful rendering, and superior user experience.
1315
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.
1619
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+
1922
<a id="toc"></a>
2023
: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)
3230

3331
:marked
34-
**See the <live-example name="cb-dynamic-form"></live-example>**.
32+
See the <live-example name="cb-dynamic-form"></live-example>.
3533

3634
.l-main-section
3735
<a id="bootstrap"></a>
3836
:marked
3937
## Bootstrap
4038

41-
We start by creating an `NgModule` called `AppModule`.
39+
Start by creating an `NgModule` called `AppModule`.
4240

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).
4642

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`.
4848

4949
+makeTabs(
5050
`cb-dynamic-form/ts/src/app/app.module.ts,
5151
cb-dynamic-form/ts/src/main.ts`,
5252
null,
5353
`app.module.ts,
5454
main.ts`
55-
)
55+
)
5656

5757
.l-main-section
5858
<a id="object-model"></a>
5959
:marked
60-
## Question Model
60+
## Question model
6161

6262
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.
6565

66-
We have created `QuestionBase` as the most fundamental question class.
66+
The following `QuestionBase` is a fundamental question class.
6767

6868
+makeExample('cb-dynamic-form/ts/src/app/question-base.ts','','src/app/question-base.ts')
6969

7070
:marked
71-
From this base we derived two new classes in `TextboxQuestion` and `DropdownQuestion` that represent Textbox and Dropdown questions.
72-
The idea is that the form will be bound to specific question types and render the appropriate controls dynamically.
73-
74-
`TextboxQuestion` supports multiple html5 types like text, email, url etc via the `type` property.
71+
From this base you can derive two new classes in `TextboxQuestion` and `DropdownQuestion`
72+
that represent textbox and dropdown questions.
73+
The idea is that the form will be bound to specific question types and render the
74+
appropriate controls dynamically.
75+
76+
`TextboxQuestion` supports multiple HTML5 types such as text, email, and url
77+
via the `type` property.
7578

7679
+makeExample('cb-dynamic-form/ts/src/app/question-textbox.ts',null,'src/app/question-textbox.ts')(format='.')
7780

7881
:marked
7982
`DropdownQuestion` presents a list of choices in a select box.
80-
83+
8184
+makeExample('cb-dynamic-form/ts/src/app/question-dropdown.ts',null,'src/app/question-dropdown.ts')(format='.')
8285

8386
:marked
84-
Next we have defined `QuestionControlService`, a simple service for transforming our questions to a `FormGroup`.
85-
In a nutshell, the form group consumes the metadata from the question model and allows us to specify default values and validation rules.
87+
Next is `QuestionControlService`, a simple service for transforming the questions to a `FormGroup`.
88+
In a nutshell, the form group consumes the metadata from the question model and
89+
allows you to specify default values and validation rules.
8690

8791
+makeExample('cb-dynamic-form/ts/src/app/question-control.service.ts',null,'src/app/question-control.service.ts')(format='.')
8892

8993
<a id="form-component"></a>
9094
:marked
9195
## Question form components
92-
Now that we have defined the complete model we are ready to create components to represent the dynamic form.
96+
Now that you have defined the complete model you are ready
97+
to create components to represent the dynamic form.
9398

9499
:marked
95-
`DynamicFormComponent` is the entry point and the main container for the form.
100+
`DynamicFormComponent` is the entry point and the main container for the form.
96101
+makeTabs(
97102
`cb-dynamic-form/ts/src/app/dynamic-form.component.html,
98103
cb-dynamic-form/ts/src/app/dynamic-form.component.ts`,
99104
null,
100105
`dynamic-form.component.html,
101106
dynamic-form.component.ts`
102-
)
107+
)
103108
:marked
104-
It presents a list of questions, each question bound to a `<df-question>` component element.
109+
It presents a list of questions, each bound to a `<df-question>` component element.
105110
The `<df-question>` tag matches the `DynamicFormQuestionComponent`,
106-
the component responsible for rendering the details of each _individual_ question based on values in the data-bound question object.
111+
the component responsible for rendering the details of each _individual_
112+
question based on values in the data-bound question object.
107113

108114
+makeTabs(
109115
`cb-dynamic-form/ts/src/app/dynamic-form-question.component.html,
@@ -113,48 +119,53 @@ include ../_util-fns
113119
dynamic-form-question.component.ts`
114120
)
115121
:marked
116-
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.
118124
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
121127
underlying control objects, populated from the question model with display and validation rules.
122128

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`.
124132

125-
<a id="questionnaire-metadata"></a>
133+
<a id="questionnaire-data"></a>
126134
:marked
127135
## Questionnaire data
128136
: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.
130146

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.
136-
137-
+makeExample('cb-dynamic-form/ts/src/app/question.service.ts','','src/app/question.service.ts')
147+
+makeExample('cb-dynamic-form/ts/src/app/question.service.ts','','src/app/question.service.ts')
138148

139149
:marked
140-
Finally, we display an instance of the form in the `AppComponent` shell.
150+
Finally, display an instance of the form in the `AppComponent` shell.
141151

142152
+makeExample('cb-dynamic-form/ts/src/app/app.component.ts','','app.component.ts')
143153

144154
<a id="dynamic-template"></a>
145155
:marked
146156
## Dynamic Template
147-
Although in this example we're modelling a job application for heroes, there are no references to any specific hero question
148-
outside the objects returned by `QuestionService`.
149-
150-
This is very important since it allows us to repurpose the components for any type of survey
151-
as long as it's compatible with our *question* object model.
152-
The key is the dynamic data binding of metadata used to render the form
153-
without making any hardcoded assumptions about specific questions.
154-
In addition to control metadata, we are also adding validation dynamically.
155-
156-
The *Save* button is disabled until the form is in a valid state.
157-
When the form is valid, we can click *Save* and the app renders the current form values as JSON.
157+
Although in this example you're modelling a job application for heroes, there are
158+
no references to any specific hero question
159+
outside the objects returned by `QuestionService`.
160+
161+
This is very important since it allows you to repurpose the components for any type of survey
162+
as long as it's compatible with the *question* object model.
163+
The key is the dynamic data binding of metadata used to render the form
164+
without making any hardcoded assumptions about specific questions.
165+
In addition to control metadata, you are also adding validation dynamically.
166+
167+
The *Save* button is disabled until the form is in a valid state.
168+
When the form is valid, you can click *Save* and the app renders the current form values as JSON.
158169
This proves that any user input is bound back to the data model.
159170
Saving and retrieving the data is an exercise for another time.
160171

0 commit comments

Comments
 (0)