Format date fields without patch form
This commit is contained in:
committed by
Arnold Gálovics
parent
9d43181cea
commit
6ea3d97538
+15
-11
@@ -6,6 +6,7 @@ import { Router, ActivatedRoute } from '@angular/router';
|
||||
/** Custom Services. */
|
||||
import { LoansService } from 'app/loans/loans.service';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
|
||||
/**
|
||||
* Waive Interest component.
|
||||
@@ -35,6 +36,7 @@ export class WaiveInterestComponent implements OnInit {
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private router: Router,
|
||||
private settingsService: SettingsService,
|
||||
private dateUtils: Dates,
|
||||
private loanService: LoansService,
|
||||
private route: ActivatedRoute) { }
|
||||
@@ -58,18 +60,20 @@ export class WaiveInterestComponent implements OnInit {
|
||||
* Submits loan interest form.
|
||||
*/
|
||||
submit() {
|
||||
const transactionDate = this.loanInterestForm.value.transactionDate;
|
||||
const transactionAmount = this.loanInterestForm.value.transactionAmount;
|
||||
const dateFormat = 'dd MMMM yyyy';
|
||||
this.loanInterestForm.patchValue({
|
||||
transactionDate: this.dateUtils.formatDate(transactionDate, dateFormat),
|
||||
transactionAmount: parseInt(transactionAmount, 10)
|
||||
});
|
||||
const loanInterestFormData = this.loanInterestForm.value;
|
||||
const locale = this.settingsService.language.code;
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const prevTransactionDate = this.loanInterestForm.value.transactionDate;
|
||||
if (loanInterestFormData.transactionDate instanceof Date) {
|
||||
loanInterestFormData.transactionDate = this.dateUtils.formatDate(prevTransactionDate, dateFormat);
|
||||
}
|
||||
const data = {
|
||||
...loanInterestFormData,
|
||||
dateFormat,
|
||||
locale
|
||||
};
|
||||
const loanId = this.route.parent.snapshot.params['loanId'];
|
||||
const loanInterestForm = this.loanInterestForm.value;
|
||||
loanInterestForm.locale = 'en';
|
||||
loanInterestForm.dateFormat = dateFormat;
|
||||
this.loanService.submitLoanActionButton(loanId, loanInterestForm, 'waiveinterest').subscribe((response: any) => {
|
||||
this.loanService.submitLoanActionButton(loanId, data, 'waiveinterest').subscribe((response: any) => {
|
||||
this.router.navigate(['../../general'], {relativeTo: this.route});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user