Commit 3109f8d3 by Muhammad Usman

forms validation reverted to helper service

parent 4188602d
......@@ -6,6 +6,7 @@ import { EXTERNAL_LINKS } from '../../config/constants';
import { AuthService } from '../../services/auth.service';
import { ToasterService } from '../../services/toaster.service';
import { UtilsService } from '../../../oneit/services/utils.service';
import { HelperService } from '../../services/helper.service';
@Component({
selector: 'app-forgot-password',
......@@ -25,14 +26,15 @@ export class ForgotPasswordComponent extends BaseComponent {
constructor(
private toasterService: ToasterService,
private authService: AuthService,
private utilsService: UtilsService
private utilsService: UtilsService,
private helperService: HelperService
) {
super();
}
forgot(): void {
if (this.form.invalid) {
return this.utilsService.showAllErrorMessages();
this.helperService.validateAllFormFields(this.form);
}
this.isLoading = true;
this.authService.forgot(this.forgotForm)
......
......@@ -7,6 +7,7 @@ import { BaseComponent } from '../../base/base.component';
import { EXTERNAL_LINKS } from '../../config/constants';
import { AuthService } from '../../services/auth.service';
import { UtilsService } from '../../../oneit/services/utils.service';
import { HelperService } from '../../services/helper.service';
@Component({
selector: 'app-login',
......@@ -28,14 +29,15 @@ export class LoginComponent extends BaseComponent {
private authService: AuthService,
private router: Router,
private appService: AppService,
private utilsService: UtilsService
private utilsService: UtilsService,
private helperService: HelperService
) {
super();
}
login(): void {
if (this.form.invalid) {
return this.utilsService.showAllErrorMessages();
this.helperService.validateAllFormFields(this.form);
}
this.isLoading = true;
this.authService.login(this.loginForm)
......
......@@ -7,6 +7,7 @@ import { EXTERNAL_LINKS } from '../../config/constants';
import { AuthService } from '../../services/auth.service';
import { ToasterService } from '../../services/toaster.service';
import { UtilsService } from '../../../oneit/services/utils.service';
import { HelperService } from '../../services/helper.service';
@Component({
selector: 'app-register',
......@@ -35,14 +36,15 @@ export class RegisterComponent extends BaseComponent {
private authService: AuthService,
private toasterService: ToasterService,
private router: Router,
private utilsService: UtilsService
private utilsService: UtilsService,
private helperService: HelperService
) {
super();
}
register(): void {
if (this.form.invalid) {
return this.utilsService.showAllErrorMessages();
this.helperService.validateAllFormFields(this.form);
}
this.registerForm.email = this.registerForm.username;
if (!this.registerForm.was_referred) {
......
......@@ -7,6 +7,7 @@ import { AuthService } from '../../services/auth.service';
import { ToasterService } from '../../services/toaster.service';
import { EXTERNAL_LINKS } from '../../config/constants';
import { UtilsService } from '../../../oneit/services/utils.service';
import { HelperService } from '../../services/helper.service';
@Component({
selector: 'app-reset-password',
......@@ -30,6 +31,7 @@ export class ResetPasswordComponent extends BaseComponent implements OnInit {
private toasterService: ToasterService,
private authService: AuthService,
private utilsService: UtilsService,
private helperService: HelperService,
private router: Router
) {
super();
......@@ -47,7 +49,7 @@ export class ResetPasswordComponent extends BaseComponent implements OnInit {
reset(): void {
if (this.form.invalid) {
return this.utilsService.showAllErrorMessages();
this.helperService.validateAllFormFields(this.form);
}
const formData = {resetToken: this.resetToken, newPassword: this.resetForm.password};
this.isLoading = true;
......
......@@ -9,6 +9,7 @@ import { takeUntil } from 'rxjs/operators';
import { CertificationModel, EducationModel } from '../../../models/education.model';
import { environment } from '../../../../../environments/environment';
import { Router } from '@angular/router';
import { HelperService } from '../../../services/helper.service';
@Component({
selector: 'app-education',
......@@ -30,6 +31,7 @@ export class EducationComponent extends BaseComponent implements OnInit {
private personalDetailsService: PersonalDetailsService,
private confirmationService: ConfirmationService,
private utilsService: UtilsService,
private helperService: HelperService,
private router: Router
) {
super();
......@@ -81,7 +83,7 @@ export class EducationComponent extends BaseComponent implements OnInit {
saveEducation(customRoute = null): void {
if (this.form.invalid) {
this.utilsService.showAllErrorMessages();
this.helperService.validateAllFormFields(this.form);
}
this.careerProfile.EducationCertificates.forEach(exp => {
if (typeof exp.Certification === 'string') {
......
......@@ -8,6 +8,7 @@ import { ConfirmationService } from 'primeng/api';
import { takeUntil } from 'rxjs/operators';
import { CareerSkillModel, SkillModel } from '../../../models/career-skill.model';
import { Router } from '@angular/router';
import { HelperService } from '../../../services/helper.service';
@Component({
selector: 'app-skills',
......@@ -28,6 +29,7 @@ export class SkillsComponent extends BaseComponent implements OnInit {
private personalDetailsService: PersonalDetailsService,
private confirmationService: ConfirmationService,
private utilsService: UtilsService,
private helperService: HelperService,
private router: Router
) {
super();
......@@ -95,7 +97,7 @@ export class SkillsComponent extends BaseComponent implements OnInit {
saveSkill(customRoute = null): void {
if (this.form.invalid) {
return this.utilsService.showAllErrorMessages();
this.helperService.validateAllFormFields(this.form);
}
this.isSaving = true;
this.personalDetailsService.saveProfile(this.createdObjs, this.updatedObjs, this.deletedObjs)
......
......@@ -8,6 +8,7 @@ import { WorkExperienceModel } from '../../../models/work-experience.model';
import { NgForm } from '@angular/forms';
import { ConfirmationService } from 'primeng/api';
import { Router } from '@angular/router';
import { HelperService } from '../../../services/helper.service';
@Component({
selector: 'app-work-history',
......@@ -27,6 +28,7 @@ export class WorkHistoryComponent extends BaseComponent implements OnInit {
private personalDetailsService: PersonalDetailsService,
private confirmationService: ConfirmationService,
private utilsService: UtilsService,
private helperService: HelperService,
private router: Router
) {
super();
......@@ -88,7 +90,7 @@ export class WorkHistoryComponent extends BaseComponent implements OnInit {
saveWorkHistory(customRoute = null): void {
if (this.form.invalid) {
return this.utilsService.showAllErrorMessages();
this.helperService.validateAllFormFields(this.form);
}
this.careerProfile.WorkExperiences.forEach(exp => {
exp.StartMonth = UtilsService.convertDateToString(exp.StartMonthField);
......
......@@ -8,6 +8,7 @@ import { PersonalDetailsService } from '../../services/personal-details.service'
import { CareerProfileModel } from '../../models/career-profile.model';
import { IntroLetterService } from '../../services/intro-letter.service';
import { NgForm } from '@angular/forms';
import { HelperService } from '../../services/helper.service';
@Component({
selector: 'app-intro-letter',
......@@ -28,6 +29,7 @@ export class IntroLetterComponent extends BaseComponent implements OnInit {
private personalDetailsService: PersonalDetailsService,
private introLetterService: IntroLetterService,
private utilsService: UtilsService,
private helperService: HelperService,
private router: Router
) {
super();
......@@ -81,7 +83,7 @@ export class IntroLetterComponent extends BaseComponent implements OnInit {
saveIntroLetter(): void {
if (this.form.invalid) {
return this.utilsService.showAllErrorMessages();
this.helperService.validateAllFormFields(this.form);
}
this.isLoading = true;
this.introLetterService.saveIntroLetters(this.createdObjs, this.updatedObjs, this.deletedObjs)
......
......@@ -8,6 +8,7 @@ import { PersonalDetailsService } from '../../services/personal-details.service'
import { ToasterService } from '../../services/toaster.service';
import { Router } from '@angular/router';
import { UtilsService } from '../../../oneit/services/utils.service';
import { HelperService } from '../../services/helper.service';
@Component({
selector: 'app-personal-details',
......@@ -34,6 +35,7 @@ export class PersonalDetailsComponent extends BaseComponent implements OnInit {
private toasterService: ToasterService,
private appService: AppService,
private utilsService: UtilsService,
private helperService: HelperService,
private router: Router
) {
super();
......@@ -103,7 +105,7 @@ export class PersonalDetailsComponent extends BaseComponent implements OnInit {
updateProfile(customRoute = null): void {
if (this.form.invalid) {
return this.utilsService.showAllErrorMessages();
this.helperService.validateAllFormFields(this.form);
}
this.careerProfile.Candidate.User.UserName = this.careerProfile.Candidate.User.Email;
this.isSaving = true;
......
......@@ -10,6 +10,7 @@ import { MyCareerWebRouting } from './my-career-web.routing';
import { AuthService } from './services/auth.service';
import { WelcomeComponent } from './welcome/welcome.component';
import { OneITModule } from '../oneit/oneit.module';
import { HelperService } from './services/helper.service';
@NgModule({
imports: [
......@@ -21,6 +22,7 @@ import { OneITModule } from '../oneit/oneit.module';
providers: [
AuthService,
MessageService,
HelperService,
PublicGuard,
HomeGuard
],
......
import { Injectable } from '@angular/core';
import { FormArray, FormControl, FormGroup } from '@angular/forms';
@Injectable()
export class HelperService {
validateAllFormFields(form?: any): void {
const formObj = typeof form.form ? form.form : form;
Object
.keys(form.controls)
.forEach(field => {
const control = formObj.get(field);
if (control instanceof FormControl) {
control.markAsDirty({onlySelf: true});
control.markAsTouched({onlySelf: true});
} else if (control instanceof FormGroup) {
this.validateAllFormFields(control);
} else if (control instanceof FormArray) {
control.controls.forEach(ctrl => {
if (ctrl instanceof FormControl) {
ctrl.markAsDirty({onlySelf: true});
ctrl.markAsTouched({onlySelf: true});
} else if (ctrl instanceof FormGroup) {
this.validateAllFormFields(ctrl);
}
});
}
});
}
}
......@@ -21,7 +21,7 @@
},
"showMenuIcon": true,
"defaultMenuIcon": "dashboard",
"showErrorAfterTouched": true,
"showErrorAfterTouched": false,
"fetchErrorMsgsFromServer": false,
"loadMessageSource": false,
"mobileBreakpoint": 1024,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment