Skip to content

Commit a9aff82

Browse files
committed
Validation visual feedback
1 parent af01601 commit a9aff82

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

reactive-forms/src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ <h2>Registration Form</h2>
44
<form [formGroup]="registrationForm">
55
<div class="form-group">
66
<label>Username</label>
7-
<input type="text" formControlName="userName" class="form-control">
7+
<input type="text" [class.is-invalid]="registrationForm.get('userName').invalid && registrationForm.get('userName').touched" formControlName="userName" class="form-control">
88
</div>
99

1010
<div class="form-group">

reactive-forms/src/app/app.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Component } from '@angular/core';
22
import { FormGroup, FormControl } from '@angular/forms';
33
import { FormBuilder } from '@angular/forms';
4+
import { Validators } from '@angular/forms';
45

56
@Component({
67
selector: 'app-root',
@@ -21,7 +22,7 @@ export class AppComponent {
2122
// });
2223

2324
registrationForm = this.fb.group({
24-
userName: [''],
25+
userName: ['', Validators.required],
2526
password: [''],
2627
confirmPassword: [''],
2728
address: this.fb.group({

0 commit comments

Comments
 (0)