Skip to content

Commit a1370e0

Browse files
Merge pull request #2792 from Varun789-mx/WEB-361
WEB-361 'Fund Mapping' search page doesn't send proper JSON to Fineract
2 parents 57f6def + 476c375 commit a1370e0

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

src/app/organization/fund-mapping/fund-mapping.component.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import {
2020
UntypedFormBuilder,
2121
UntypedFormControl,
2222
Validators,
23-
ReactiveFormsModule
23+
ReactiveFormsModule,
24+
AbstractControl,
25+
ValidationErrors
2426
} from '@angular/forms';
2527
import { ActivatedRoute, RouterLink } from '@angular/router';
2628

@@ -112,14 +114,36 @@ export class FundMappingComponent implements OnInit {
112114
this.buildDependencies();
113115
}
114116

117+
/**
118+
* Custom validator to ensure array fields are not empty.
119+
* @param {AbstractControl} control - the form control to validate.
120+
* @returns {ValidationErrors | null} - validation errors or null if valid.
121+
*/
122+
private nonEmptyArrayValidator(control: AbstractControl): ValidationErrors | null {
123+
const value = control.value;
124+
if (!value || !Array.isArray(value) || value.length === 0) {
125+
return { required: true };
126+
}
127+
if (value.every((item: any) => item === '' || item === null || item === undefined)) {
128+
return { required: true };
129+
}
130+
return null;
131+
}
132+
115133
/**
116134
* Creates the Fund Mapping Form
117135
*/
118136
createFundMappingForm() {
119137
this.fundMappingForm = this.formBuilder.group({
120-
loanStatus: [''],
121-
loanProducts: [''],
122-
offices: [''],
138+
loanStatus: [
139+
[],
140+
this.nonEmptyArrayValidator.bind(this)],
141+
loanProducts: [
142+
[],
143+
this.nonEmptyArrayValidator.bind(this)],
144+
offices: [
145+
[],
146+
this.nonEmptyArrayValidator.bind(this)],
123147
loanDateOption: [
124148
'',
125149
Validators.required
@@ -224,6 +248,10 @@ export class FundMappingComponent implements OnInit {
224248
if (fundMappingFormData.loanFromDate instanceof Date) {
225249
fundMappingFormData.loanFromDate = this.dateUtils.formatDate(prevLoanFromDate, dateFormat);
226250
}
251+
if (this.fundMappingForm.invalid) {
252+
this.fundMappingForm.markAllAsTouched();
253+
return;
254+
}
227255
if (fundMappingFormData.loanToDate instanceof Date) {
228256
fundMappingFormData.loanToDate = this.dateUtils.formatDate(prevLoanToDate, dateFormat);
229257
}

0 commit comments

Comments
 (0)