diff --git a/v2/registrar/registration/location-information/location-information.component.ts b/v2/registrar/registration/location-information/location-information.component.ts index 7632bc4..1051584 100644 --- a/v2/registrar/registration/location-information/location-information.component.ts +++ b/v2/registrar/registration/location-information/location-information.component.ts @@ -79,26 +79,23 @@ export class LocationInformationComponent { ngOnInit() { this.formData.forEach((item: any) => { + const validators = []; + if (item.isRequired) { + validators.push(Validators.required); + } if (item.fieldName && item.allowText) { - this.locationInfoFormGroup.addControl( - item.fieldName, - new FormControl(null, [ - Validators.pattern(this.allowTextValidator(item.allowText)), - Validators.minLength(parseInt(item?.allowMin)), - Validators.maxLength(parseInt(item?.allowMax)), - ]), - ); - } else { - this.locationInfoFormGroup.addControl( - item.fieldName, - new FormControl(null), + validators.push( + Validators.pattern(this.allowTextValidator(item.allowText)), + Validators.minLength(Number.parseInt(item?.allowMin)), + Validators.maxLength(Number.parseInt(item?.allowMax)) ); - // Initialize filtered list with all options - if (item.options) { - this.filteredOptions[item.fieldName] = [...item.options]; - } + } else if (item.options) { + this.filteredOptions[item.fieldName] = [...item.options]; } - + this.locationInfoFormGroup.addControl( + item.fieldName, + new FormControl(null, validators) + ); }); this.locationInfoFormGroup.addControl('stateID', new FormControl()); this.locationInfoFormGroup.addControl('districtID', new FormControl()); diff --git a/v2/registrar/registration/other-information/other-information.component.ts b/v2/registrar/registration/other-information/other-information.component.ts index 7003c7e..a16e769 100644 --- a/v2/registrar/registration/other-information/other-information.component.ts +++ b/v2/registrar/registration/other-information/other-information.component.ts @@ -81,21 +81,21 @@ export class OtherInformationComponent { ngOnInit() { console.log('this.otherInfoSubscription', this.otherInfoSubscription); this.formData.forEach((item: any) => { + const validators = []; + if (item.isRequired) { + validators.push(Validators.required); + } if (item.fieldName && item.allowText) { - this.otherInfoFormGroup.addControl( - item.fieldName, - new FormControl(null, [ - Validators.pattern(this.allowTextValidator(item.allowText)), - Validators.minLength(parseInt(item?.allowMin)), - Validators.maxLength(parseInt(item?.allowMax)), - ]), - ); - } else { - this.otherInfoFormGroup.addControl( - item.fieldName, - new FormControl(null), + validators.push( + Validators.pattern(this.allowTextValidator(item.allowText)), + Validators.minLength(Number.parseInt(item?.allowMin)), + Validators.maxLength(Number.parseInt(item?.allowMax)) ); } + this.otherInfoFormGroup.addControl( + item.fieldName, + new FormControl(null, validators) + ); }); console.log('otherInfoFormGroup Data', this.otherInfoFormGroup); if (this.patientRevisit) diff --git a/v2/registrar/registration/personal-information/personal-information.component.ts b/v2/registrar/registration/personal-information/personal-information.component.ts index ce793af..a289839 100644 --- a/v2/registrar/registration/personal-information/personal-information.component.ts +++ b/v2/registrar/registration/personal-information/personal-information.component.ts @@ -104,19 +104,27 @@ export class PersonalInformationComponent { this.isEnableES = environment.isEnableES || false; this.fetchLanguageResponse(); this.formData.forEach((item: any) => { + const validators = []; + if (item.isRequired) { + validators.push(Validators.required); + } if (item.fieldName && item.allowText) { - this.personalInfoFormGroup.addControl( - item.fieldName, - new FormControl(null, [ - Validators.pattern(this.allowTextValidator(item.allowText)), - Validators.minLength(parseInt(item?.allowMin)), - Validators.maxLength(parseInt(item?.allowMax)), - ]) + validators.push( + Validators.pattern(this.allowTextValidator(item.allowText)), + Validators.minLength(Number.parseInt(item?.allowMin)), + Validators.maxLength(Number.parseInt(item?.allowMax)) ); + } + const existing = this.personalInfoFormGroup.get(item.fieldName); + if (existing) { + if (validators.length) { + existing.addValidators(validators); + existing.updateValueAndValidity({ emitEvent: false }); + } } else { this.personalInfoFormGroup.addControl( item.fieldName, - new FormControl(null) + new FormControl(null, validators) ); } }); diff --git a/v2/registrar/registration/registration.component.ts b/v2/registrar/registration/registration.component.ts index 506ce34..35e594e 100644 --- a/v2/registrar/registration/registration.component.ts +++ b/v2/registrar/registration/registration.component.ts @@ -172,7 +172,32 @@ export class RegistrationComponent { return this.currentStep >= this.enabledStepKeys.length - 1; } + private stepFormGroup(key: string): FormGroup | null { + switch (key) { + case 'personal': + return this.personalInfoFormGroup; + case 'location': + return this.locationInfoFormGroup; + case 'other': + return this.otherInfoFormGroup; + case 'abha': + return this.abhaInfoFormGroup; + default: + return null; + } + } + nextStep() { + const group = this.stepFormGroup(this.activeStepKey); + if (group?.invalid) { + group.markAllAsTouched(); + this.confirmationService.alert( + this.currentLanguageSet?.alerts?.info?.mandatoryFields || + 'Please fill all the mandatory fields', + 'info' + ); + return; + } if (this.currentStep < this.enabledStepKeys.length - 1) { this.currentStep++; } @@ -335,6 +360,15 @@ export class RegistrationComponent { submitBeneficiaryDetails() { + if (this.mainForm.invalid) { + this.mainForm.markAllAsTouched(); + this.confirmationService.alert( + this.currentLanguageSet?.alerts?.info?.mandatoryFields || + 'Please fill all the mandatory fields', + 'info' + ); + return; + } console.log('registration data', this.mainForm); const newDate = this.dateFormatChange(); const valueToSend = this.mainForm.value; diff --git a/v2/registrar/search/search.component.ts b/v2/registrar/search/search.component.ts index 751c7a7..d6629c0 100644 --- a/v2/registrar/search/search.component.ts +++ b/v2/registrar/search/search.component.ts @@ -178,7 +178,10 @@ export class SearchComponent implements OnInit, DoCheck, AfterViewChecked, OnDes this.handleESSearchResponse(response); }, (error: any) => { - this.confirmationService.alert(error, 'error'); + this.confirmationService.alert( + error?.error?.errorMessage || error?.message || 'Something went wrong', + 'error', + ); } ); } @@ -220,7 +223,10 @@ export class SearchComponent implements OnInit, DoCheck, AfterViewChecked, OnDes this.handleESSearchResponse(response); }, (error: any) => { - this.confirmationService.alert(error, 'error'); + this.confirmationService.alert( + error?.error?.errorMessage || error?.message || 'Something went wrong', + 'error', + ); } ); } else { @@ -370,7 +376,8 @@ export class SearchComponent implements OnInit, DoCheck, AfterViewChecked, OnDes if (!beneficiaryList || beneficiaryList.length <= 0) { this.resetWorklist(); this.confirmationService.alert( - this.currentLanguageSet.alerts.info.beneficiarynotfound, + this.currentLanguageSet?.alerts?.info?.beneficiarynotfound || + 'Beneficiary not found', 'info', ); } else { @@ -381,12 +388,16 @@ export class SearchComponent implements OnInit, DoCheck, AfterViewChecked, OnDes console.log('hi', JSON.stringify(beneficiaryList, null, 4)); }, (error) => { - this.confirmationService.alert(error, 'error'); + this.confirmationService.alert( + error?.error?.errorMessage || error?.message || 'Something went wrong', + 'error', + ); }, ); } else { this.confirmationService.alert( - this.currentLanguageSet.alerts.info.phoneDetails, + this.currentLanguageSet?.alerts?.info?.phoneDetails || + 'Please enter the required search details', 'info', ); } @@ -554,7 +565,10 @@ export class SearchComponent implements OnInit, DoCheck, AfterViewChecked, OnDes else this.confirmationService.alert(result.status, 'warn'); }, (error) => { - this.confirmationService.alert(error, 'error'); + this.confirmationService.alert( + error?.error?.errorMessage || error?.message || 'Something went wrong', + 'error', + ); }, ); } @@ -604,7 +618,9 @@ export class SearchComponent implements OnInit, DoCheck, AfterViewChecked, OnDes this.resetWorklist(); this.quicksearchTerm = null; this.confirmationService.alert( - this.currentLanguageSet.alerts.info.beneficiaryNotFound, + this.currentLanguageSet?.alerts?.info?.beneficiarynotfound || + this.currentLanguageSet?.alerts?.info?.beneficiaryNotFound || + 'Beneficiary not found', 'info', ); } else { @@ -614,7 +630,10 @@ export class SearchComponent implements OnInit, DoCheck, AfterViewChecked, OnDes console.log('ES Advanced Search Result:', JSON.stringify(response, null, 4)); }, (error) => { - this.confirmationService.alert(error, 'error'); + this.confirmationService.alert( + error?.error?.errorMessage || error?.message || 'Something went wrong', + 'error', + ); }, ); } else { @@ -630,7 +649,9 @@ export class SearchComponent implements OnInit, DoCheck, AfterViewChecked, OnDes this.resetWorklist(); this.quicksearchTerm = null; this.confirmationService.alert( - this.currentLanguageSet.alerts.info.beneficiaryNotFound, + this.currentLanguageSet?.alerts?.info?.beneficiarynotfound || + this.currentLanguageSet?.alerts?.info?.beneficiaryNotFound || + 'Beneficiary not found', 'info', ); } else { @@ -639,7 +660,10 @@ export class SearchComponent implements OnInit, DoCheck, AfterViewChecked, OnDes console.log(JSON.stringify(beneficiaryList, null, 4)); }, (error) => { - this.confirmationService.alert(error, 'error'); + this.confirmationService.alert( + error?.error?.errorMessage || error?.message || 'Something went wrong', + 'error', + ); }, ); } diff --git a/v2/ui/paginator/paginator.component.ts b/v2/ui/paginator/paginator.component.ts index d6559e7..7a2b236 100644 --- a/v2/ui/paginator/paginator.component.ts +++ b/v2/ui/paginator/paginator.component.ts @@ -71,6 +71,7 @@ import { mergeClasses } from '../utils/merge-classes'; }