Skip to content

Commit

Permalink
nie ma błędów podczas ładowania formularza addExpense
Browse files Browse the repository at this point in the history
  • Loading branch information
JanisBe committed Jun 7, 2024
1 parent c7a27ca commit d6cf6ad
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,10 @@ export class AddExpenseComponent implements OnInit, OnDestroy {
console.log(expense);
this.currentExpense = expense;
this.debts = expense.debt;
this.initForm();
this.form.patchValue(this.currentExpense);
});
} else {
this.initForm();
}
this.initForm();
this.groupService.findById(this.data.groupId).subscribe(group => {
this.currentGroup = group;
this.currentGroupName$ = of(this.currentGroup.groupName);
Expand All @@ -110,15 +108,13 @@ export class AddExpenseComponent implements OnInit, OnDestroy {
});
this.currencyService.getDefaultCurrencyForGroup(this.data.groupId)
.subscribe(response => {
console.log(response);
this.defaultCurrency = response;
this.form.get('currency')?.patchValue(this.defaultCurrency)
});

this.categoryService.findAllCategories().subscribe(category => this.categories = category);
this.currencies = this.currencyService.getAllCurrencies();
this.loadingService.setLoading(false);
this.listenForAmountChange();
}

onCancel() {
Expand Down Expand Up @@ -234,6 +230,7 @@ export class AddExpenseComponent implements OnInit, OnDestroy {
date: new FormControl(this.currentExpense?.date ?? new Date(), Validators.required)
});
this.loadingService.setLoading(false);
this.listenForAmountChange();
}

private calculateAmount(expense: Expense): number {
Expand Down Expand Up @@ -343,7 +340,7 @@ export class AddExpenseComponent implements OnInit, OnDestroy {

private listenForAmountChange() {
this.form.controls['amount'].valueChanges.subscribe((val: string) => {
if (!val.match(this.AMOUNT_PATTERN)) {
if (!val.toString().match(this.AMOUNT_PATTERN)) {
this.form.controls['amount'].setErrors({invalidAmount: true}) // <--- Set invalidAmount to true
} else {
this.form.controls['amount'].setErrors(null)
Expand Down

0 comments on commit d6cf6ad

Please sign in to comment.