WEB-361 'Fund Mapping' search page doesn't send proper JSON to Fineract
This commit is contained in:
@@ -20,7 +20,9 @@ import {
|
|||||||
UntypedFormBuilder,
|
UntypedFormBuilder,
|
||||||
UntypedFormControl,
|
UntypedFormControl,
|
||||||
Validators,
|
Validators,
|
||||||
ReactiveFormsModule
|
ReactiveFormsModule,
|
||||||
|
AbstractControl,
|
||||||
|
ValidationErrors
|
||||||
} from '@angular/forms';
|
} from '@angular/forms';
|
||||||
import { ActivatedRoute, RouterLink } from '@angular/router';
|
import { ActivatedRoute, RouterLink } from '@angular/router';
|
||||||
|
|
||||||
@@ -112,14 +114,36 @@ export class FundMappingComponent implements OnInit {
|
|||||||
this.buildDependencies();
|
this.buildDependencies();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom validator to ensure array fields are not empty.
|
||||||
|
* @param {AbstractControl} control - the form control to validate.
|
||||||
|
* @returns {ValidationErrors | null} - validation errors or null if valid.
|
||||||
|
*/
|
||||||
|
private nonEmptyArrayValidator(control: AbstractControl): ValidationErrors | null {
|
||||||
|
const value = control.value;
|
||||||
|
if (!value || !Array.isArray(value) || value.length === 0) {
|
||||||
|
return { required: true };
|
||||||
|
}
|
||||||
|
if (value.every((item: any) => item === '' || item === null || item === undefined)) {
|
||||||
|
return { required: true };
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the Fund Mapping Form
|
* Creates the Fund Mapping Form
|
||||||
*/
|
*/
|
||||||
createFundMappingForm() {
|
createFundMappingForm() {
|
||||||
this.fundMappingForm = this.formBuilder.group({
|
this.fundMappingForm = this.formBuilder.group({
|
||||||
loanStatus: [''],
|
loanStatus: [
|
||||||
loanProducts: [''],
|
[],
|
||||||
offices: [''],
|
this.nonEmptyArrayValidator.bind(this)],
|
||||||
|
loanProducts: [
|
||||||
|
[],
|
||||||
|
this.nonEmptyArrayValidator.bind(this)],
|
||||||
|
offices: [
|
||||||
|
[],
|
||||||
|
this.nonEmptyArrayValidator.bind(this)],
|
||||||
loanDateOption: [
|
loanDateOption: [
|
||||||
'',
|
'',
|
||||||
Validators.required
|
Validators.required
|
||||||
@@ -224,6 +248,10 @@ export class FundMappingComponent implements OnInit {
|
|||||||
if (fundMappingFormData.loanFromDate instanceof Date) {
|
if (fundMappingFormData.loanFromDate instanceof Date) {
|
||||||
fundMappingFormData.loanFromDate = this.dateUtils.formatDate(prevLoanFromDate, dateFormat);
|
fundMappingFormData.loanFromDate = this.dateUtils.formatDate(prevLoanFromDate, dateFormat);
|
||||||
}
|
}
|
||||||
|
if (this.fundMappingForm.invalid) {
|
||||||
|
this.fundMappingForm.markAllAsTouched();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (fundMappingFormData.loanToDate instanceof Date) {
|
if (fundMappingFormData.loanToDate instanceof Date) {
|
||||||
fundMappingFormData.loanToDate = this.dateUtils.formatDate(prevLoanToDate, dateFormat);
|
fundMappingFormData.loanToDate = this.dateUtils.formatDate(prevLoanToDate, dateFormat);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user