File tree Expand file tree Collapse file tree 2 files changed +23
-7
lines changed Expand file tree Collapse file tree 2 files changed +23
-7
lines changed Original file line number Diff line number Diff line change 1212 < div class ="form-group mb-2 ">
1313 < label for ="themeTitle "> Theme for the next QAGuild podcast episode</ label >
1414 < input type ="text " formControlName ="title " placeholder ="Theme text " name ="title " class ="form-control " id ="themeTitle " required >
15- < div *ngIf ="added " class ="valid-feedback ">
15+ <!-- < div *ngIf="submitted && added" class="valid-feedback">
1616 Your record sucesfully added! Thank you!
17- </ div >
18- < div *ngIf ="error " class ="invalid-feedback ">
17+ </div> -->
18+ < div *ngIf ="submitted && error " class ="invalid-feedback ">
1919 {{ error.error.message }}
2020 </ div >
21+ < div *ngIf ="submitted && f.title.errors " class ="invalid-feedback ">
22+ < div *ngIf ="f.title.errors.required || f.title.errors.minlength "> Field must be at least 10 characters</ div >
23+ </ div >
2124 </ div >
2225 < button type ="submit " class ="btn btn-outline-success "> Add theme</ button >
2326 </ form >
Original file line number Diff line number Diff line change @@ -14,8 +14,10 @@ export class ProposeThemeComponent implements OnInit {
1414
1515 addForm : FormGroup ;
1616 themes : Theme [ ] ;
17- added : boolean
18- error : Object
17+ error : Object ;
18+ validation : string ;
19+ submitted :boolean = false ;
20+ added : boolean = false ;
1921
2022 constructor ( private formBuilder : FormBuilder ,
2123 private router : Router ,
@@ -24,19 +26,30 @@ export class ProposeThemeComponent implements OnInit {
2426
2527 ngOnInit ( ) {
2628 this . addForm = this . formBuilder . group ( {
27- title : [ '' , Validators . required ]
29+ title : [ '' , [ Validators . required , Validators . minLength ( 10 ) ] ]
2830 } ) ;
2931 this . episodeService . getAllThemesWithoutEpisode ( ) . subscribe ( data => this . themes = data ) ;
3032 }
3133
34+ // convenience getter for easy access to form fields
35+ get f ( ) { return this . addForm . controls ; }
36+
37+
3238 onSubmit ( ) {
39+ this . submitted = true ;
40+ // stop here if form is invalid
41+ if ( this . addForm . invalid ) {
42+ return ;
43+ }
44+
3345 this . episodeService . addFreeTheme ( this . addForm . value )
3446 . subscribe ( data => {
3547 this . addForm . reset ( )
3648 this . getAllThemesWithoutEpisode ( ) ;
37- this . added = true ;
49+ this . submitted = false ;
3850 } ,
3951 error => {
52+ this . submitted = false ;
4053 console . error ( error )
4154 this . error = error ;
4255 } ) ;
You can’t perform that action at this time.
0 commit comments