Format date fields without patch form
This commit is contained in:
committed by
Arnold Gálovics
parent
9d43181cea
commit
6ea3d97538
@@ -1,12 +1,12 @@
|
||||
/** Angular Imports */
|
||||
import { Component, OnInit, Input } from '@angular/core';
|
||||
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
|
||||
import { DatePipe } from '@angular/common';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
/** Custom Services */
|
||||
import { SharesService } from 'app/shares/shares.service';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
|
||||
/**
|
||||
* Apply Shares Component
|
||||
@@ -33,14 +33,14 @@ export class ApplySharesComponent implements OnInit {
|
||||
/**
|
||||
* @param {FormBuilder} formBuilder Form Builder
|
||||
* @param {SharesService} sharesService Shares Service
|
||||
* @param {DatePipe} datePipe Date Pipe
|
||||
* @param {Dates} dateUtils Date Utils
|
||||
* @param {ActivatedRoute} route Activated Route
|
||||
* @param {Router} router Router
|
||||
* @param {SettingsService} settingsService Settings Service
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private sharesService: SharesService,
|
||||
private datePipe: DatePipe,
|
||||
private dateUtils: Dates,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private settingsService: SettingsService) {
|
||||
@@ -76,15 +76,15 @@ export class ApplySharesComponent implements OnInit {
|
||||
* if successful redirects to the share account.
|
||||
*/
|
||||
submit() {
|
||||
// TODO: Update once language and date settings are setup
|
||||
const applySharesFormData = this.applySharesForm.value;
|
||||
const locale = this.settingsService.language.code;
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const prevRequestedDate: Date = this.applySharesForm.value.requestedDate;
|
||||
this.applySharesForm.patchValue({
|
||||
requestedDate: this.datePipe.transform(prevRequestedDate, dateFormat),
|
||||
});
|
||||
if (applySharesFormData.requestedDate instanceof Date) {
|
||||
applySharesFormData.requestedDate = this.dateUtils.formatDate(prevRequestedDate, dateFormat);
|
||||
}
|
||||
const data = {
|
||||
...this.applySharesForm.value,
|
||||
...applySharesFormData,
|
||||
unitPrice: this.applySharesForm.get('unitPrice').value,
|
||||
dateFormat,
|
||||
locale
|
||||
|
||||
Reference in New Issue
Block a user