Skip to content

Commit 7183b77

Browse files
committed
form array completed
1 parent 77e19c4 commit 7183b77

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

src/app/reactive/signup/signup.component.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ <h2>Welcome on board!</h2>
4242
<div class="control-row">
4343
<div class="control">
4444
<label for="street">Street</label>
45-
<input type="text" id="street" name="street" formArrayName="street" />
45+
<input type="text" id="street" name="street" formControlName="street" />
4646
</div>
4747

4848
<div class="control">
@@ -70,7 +70,7 @@ <h2>Welcome on board!</h2>
7070
<div class="control-row">
7171
<div class="control">
7272
<label for="role">What best describes your role?</label>
73-
<select id="role" name="role">
73+
<select id="role" name="role" formControlName="role">
7474
<option value="student">Student</option>
7575
<option value="teacher">Teacher</option>
7676
<option value="employee">Employee</option>
@@ -85,43 +85,43 @@ <h2>Welcome on board!</h2>
8585
<div class="control-row">
8686
<label for="role"> Your Gender </label>
8787
<div class="radio">
88-
<input type="radio" id="male" name="genger" value="male" />
88+
<input type="radio" id="male" name="gender" value="male" formControlName="gender" />
8989
<label for="html">Male</label>
9090
</div>
9191
<div class="radio">
92-
<input type="radio" id="female" name="genger" value="female" />
92+
<input type="radio" id="female" name="gender" value="female" formControlName="gender" />
9393
<label for="css">Female</label>
9494
</div>
9595
<div class="radio">
96-
<input type="radio" id="others" name="genger" value="others" />
96+
<input type="radio" id="others" name="gender" value="others" formControlName="gender" />
9797
<label for="html">Not Ready To Tell</label>
9898
</div>
9999
</div>
100100

101101
<br />
102102

103-
<fieldset>
103+
<fieldset formArrayName="source">
104104
<legend>How did you find us?</legend>
105105
<div class="control">
106-
<input type="checkbox" id="google" name="acquisition" value="google" />
106+
<input type="checkbox" id="google" name="acquisition" value="google" formControlName="0" />
107107
<label for="google">Google</label>
108108
</div>
109109

110110
<div class="control">
111-
<input type="checkbox" id="friend" name="acquisition" value="friend" />
111+
<input type="checkbox" id="friend" name="acquisition" value="friend" formControlName="1" />
112112
<label for="friend">Referred by friend</label>
113113
</div>
114114

115115
<div class="control">
116-
<input type="checkbox" id="other" name="acquisition" value="other" />
116+
<input type="checkbox" id="other" name="acquisition" value="other" formControlName="2" />
117117
<label for="other">Other</label>
118118
</div>
119119
</fieldset>
120120

121121
<div class="control-row">
122122
<div class="control">
123123
<label for="terms-and-conditions">
124-
<input type="checkbox" id="terms-and-conditions" name="terms" />
124+
<input type="checkbox" id="terms-and-conditions" name="terms" formControlName="agree" />
125125
I agree to the terms and conditions
126126
</label>
127127
</div>

src/app/reactive/signup/signup.component.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component } from '@angular/core';
2-
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
2+
import { FormArray, FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
33

44
@Component({
55
selector: 'app-signup',
@@ -43,10 +43,19 @@ export class SignupComponent {
4343
validators: [Validators.required],
4444
}),
4545
}),
46+
role: new FormControl<'student' | 'teacher' | 'employee' | 'founder' | 'other'>('student', {
47+
validators: [Validators.required],
48+
}),
49+
gender: new FormControl<'male' | 'female' | 'others' | null>(null, {
50+
validators: [Validators.required],
51+
}),
52+
source: new FormArray([new FormControl(false), new FormControl(false), new FormControl(false)]),
53+
agree: new FormControl(false, { validators: [Validators.required] }),
4654
});
4755

4856
onSubmit() {
49-
console.log(this.formObj.value);
57+
console.log('this.formObj => ', this.formObj);
58+
console.log('this.formObj.value => ', this.formObj.value);
5059
}
5160

5261
onReset() {

0 commit comments

Comments
 (0)