Skip to content

Commit 3b903bc

Browse files
author
majid noureddine
committed
add form validation
1 parent 7a47929 commit 3b903bc

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/app/edit-appareil/edit-appareil.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
<label for="name">
66
Nom de l'appareil
77
</label>
8-
<input type="text" id="name" class="form-control" name="name" ngModel>
8+
<input type="text" id="name" class="form-control" name="name" ngModel required>
99
</div>
1010
<div class="form-group">
1111
<label for="status">
1212
État de l'appareil
1313
</label>
14-
<select id="status" class="form-control" name="status" ngModel>
14+
<select id="status" class="form-control" name="status" [ngModel]="defaultOnOff">
1515
<option value="allumé">Allumé</option>
1616
<option value="éteint">Éteint</option>
1717
</select>
1818
</div>
19-
<button class="btn btn-primary" type="submit">Enregistrer</button>
19+
<button class="btn btn-primary" type="submit" [disabled]="f.invalid">Enregistrer</button>
2020
</form>
2121
</div>
2222
</div>

src/app/edit-appareil/edit-appareil.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { NgForm } from '@angular/forms';
88
})
99
export class EditAppareilComponent implements OnInit {
1010

11+
defaultOnOff = 'éteint';
12+
1113
constructor() { }
1214

1315
ngOnInit(): void {

0 commit comments

Comments
 (0)