Skip to content

Commit c34cb01

Browse files
committed
fix(forms): updated form examples to contain select elements
1 parent f1541e6 commit c34cb01

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

modules/examples/src/model_driven_forms/index.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
import {bootstrap, onChange, NgIf, Component, Directive, View, Ancestor} from 'angular2/angular2';
1+
import {
2+
bootstrap,
3+
onChange,
4+
NgIf,
5+
NgFor,
6+
Component,
7+
Directive,
8+
View,
9+
Ancestor
10+
} from 'angular2/angular2';
211
import {formDirectives, NgControl, Validators, NgFormModel, FormBuilder} from 'angular2/forms';
312

413
import {RegExpWrapper, print, isPresent} from 'angular2/src/facade/lang';
@@ -86,6 +95,13 @@ class ShowError {
8695
<show-error control="lastName" [errors]="['required']"></show-error>
8796
</p>
8897
98+
<p>
99+
<label for="country">Country</label>
100+
<select id="country" ng-control="country">
101+
<option *ng-for="#c of countries" [value]="c">{{c}}</option>
102+
</select>
103+
</p>
104+
89105
<p>
90106
<label for="creditCard">Credit Card</label>
91107
<input type="text" id="creditCard" ng-control="creditCard">
@@ -113,16 +129,18 @@ class ShowError {
113129
<button type="submit" [disabled]="!f.form.valid">Submit</button>
114130
</form>
115131
`,
116-
directives: [formDirectives, ShowError]
132+
directives: [formDirectives, NgFor, ShowError]
117133
})
118134
class ModelDrivenForms {
119135
form;
136+
countries = ['US', 'Canada'];
120137

121138
constructor(fb: FormBuilder) {
122139
this.form = fb.group({
123140
"firstName": ["", Validators.required],
124141
"middleName": [""],
125142
"lastName": ["", Validators.required],
143+
"country": ["Canada", Validators.required],
126144
"creditCard": ["", Validators.compose([Validators.required, creditCardValidator])],
127145
"amount": [0, Validators.required],
128146
"email": ["", Validators.required],

modules/examples/src/template_driven_forms/index.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
import {bootstrap, onChange, NgIf, Component, Directive, View, Ancestor} from 'angular2/angular2';
1+
import {
2+
bootstrap,
3+
onChange,
4+
NgIf,
5+
NgFor,
6+
Component,
7+
Directive,
8+
View,
9+
Ancestor
10+
} from 'angular2/angular2';
211
import {formDirectives, NgControl, Validators, NgForm} from 'angular2/forms';
312

413
import {RegExpWrapper, print, isPresent} from 'angular2/src/facade/lang';
@@ -13,6 +22,7 @@ class CheckoutModel {
1322
firstName: string;
1423
middleName: string;
1524
lastName: string;
25+
country: string = "Canada";
1626

1727
creditCard: string;
1828
amount: number;
@@ -107,6 +117,13 @@ class ShowError {
107117
<show-error control="lastName" [errors]="['required']"></show-error>
108118
</p>
109119
120+
<p>
121+
<label for="country">Country</label>
122+
<select id="country" ng-control="country" [(ng-model)]="model.country">
123+
<option *ng-for="#c of countries" [value]="c">{{c}}</option>
124+
</select>
125+
</p>
126+
110127
<p>
111128
<label for="creditCard">Credit Card</label>
112129
<input type="text" id="creditCard" ng-control="creditCard" [(ng-model)]="model.creditCard" required credit-card>
@@ -134,10 +151,11 @@ class ShowError {
134151
<button type="submit" [disabled]="!f.form.valid">Submit</button>
135152
</form>
136153
`,
137-
directives: [formDirectives, CreditCardValidator, ShowError]
154+
directives: [formDirectives, NgFor, CreditCardValidator, ShowError]
138155
})
139156
class TemplateDrivenForms {
140157
model = new CheckoutModel();
158+
countries = ['US', 'Canada'];
141159

142160
onSubmit() {
143161
print("Submitting:");

0 commit comments

Comments
 (0)