@@ -26,8 +26,8 @@ export class PutEmployeeComponent implements OnInit {
2626'emailDomain' :"Email domain must be from email.com" ,
2727'required' :"email is required"
2828} ,
29- phone :{
30- minLength :"must be 5 characters at least" ,
29+ phone :{
30+ minLength :"must be 5 characters at least" ,
3131maxLength :"not more than 20 charecters"
3232} ,
3333skillName :{
@@ -44,7 +44,7 @@ export class PutEmployeeComponent implements OnInit {
4444formErr = {
4545'fullName' :'' ,
4646'email' :'' ,
47- 'phone' :''
47+ 'phone' :''
4848// 'skills': [{
4949// 'skillName': '',
5050// 'expInYear': '',
@@ -58,7 +58,7 @@ export class PutEmployeeComponent implements OnInit {
5858this . employeeForm = new FormGroup ( {
5959fullName :new FormControl ( '' ,
6060[ Validators . required , Validators . maxLength ( 25 ) , Validators . minLength ( 2 ) ] ) ,
61- phone :new FormControl ( '' , [ Validators . minLength ( 5 ) , Validators . maxLength ( 20 ) ] ) ,
61+ phone :new FormControl ( '' , [ Validators . minLength ( 5 ) , Validators . maxLength ( 20 ) ] ) ,
6262email :new FormControl ( '' , [ Validators . required , CustomValidator . email , CustomValidator . emailDomain ( 'email.com' ) ] ) ,
6363skills :this . fb . array ( [
6464this . addSkill ( )
@@ -76,12 +76,12 @@ export class PutEmployeeComponent implements OnInit {
7676}
7777loadEmployee ( emp :IEmployee ) {
7878this . employee = emp ;
79- this . employeeForm . setControl ( 'skills' , this . loadSkills ( this . employee . skills ) ) ;
79+ this . employeeForm . setControl ( 'skills' , this . loadSkills ( this . employee . skills ) ) ;
8080this . employeeForm . patchValue ( this . employee ) ;
8181}
82- loadSkills ( skills :ISkill [ ] ) :FormArray {
82+ loadSkills ( skills :ISkill [ ] ) :FormArray {
8383let formArr = new FormArray ( [ ] ) ;
84- skills . forEach ( s => {
84+ skills . forEach ( s => {
8585formArr . push ( this . addSkill ( ) ) ;
8686} ) ;
8787return formArr ;
@@ -93,28 +93,34 @@ export class PutEmployeeComponent implements OnInit {
9393} else {
9494//submit form
9595console . log ( this . employeeForm ) ;
96- if ( this . editId ) {
97- this . ds . putEmployee ( this . employeeForm . value , this . editId ) . subscribe (
96+ if ( this . editId ) {
97+ this . ds . putEmployee ( this . employeeForm . value , this . editId ) . subscribe (
9898( data ) => {
9999this . employee = data ;
100100this . loadEmployee ( this . employee ) ;
101101} ,
102- ( err ) => console . log ( err )
102+ ( err ) => console . log ( err ) ,
103+ ( ) => {
104+ this . employeeForm . markAsUntouched ( ) ;
105+ alert ( "Data has been saved!" ) ;
106+ }
103107) ;
104- } else {
108+ } else {
105109this . ds . postEmployee ( this . employeeForm . value ) . subscribe (
106110( data ) => this . employee = data ,
107- ( err ) => console . log ( err )
111+ ( err ) => console . log ( err ) ,
112+ ( ) => {
113+ this . employeeForm . markAsUntouched ( ) ;
114+ alert ( "Data has been saved!" ) ;
115+ }
108116) ;
109117}
110- this . employeeForm . markAsUntouched ( ) ;
111- alert ( "Data has been saved!" )
112118}
113119}
114120onAddSkillBtn_Click ( ) {
115121( this . employeeForm . get ( 'skills' ) as FormArray ) . push ( this . addSkill ( ) ) ;
116122}
117- onDelSkill_Click ( index :number ) {
123+ onDelSkill_Click ( index :number ) {
118124let skillSet = ( this . employeeForm . get ( 'skills' ) as FormArray ) ;
119125skillSet . removeAt ( index ) ;
120126skillSet . markAsTouched ( ) ;
@@ -126,7 +132,7 @@ export class PutEmployeeComponent implements OnInit {
126132const fc = fg . get ( key ) ;
127133
128134this . formErr [ key ] = '' ;
129- if ( fc . touched || fc . dirty || fc . value != '' )
135+ if ( fc . touched || fc . dirty || fc . value != '' )
130136for ( const errKey in fc . errors ) {
131137if ( Object . prototype . hasOwnProperty . call ( fc . errors , errKey ) ) {
132138const errMsg = this . validationMessages [ key ] [ errKey ] ;