Add important validators #134

This commit is contained in:
kevinpauer 2022-05-07 19:11:05 +02:00
parent 55db2069f7
commit 9dc3eb28cb
3 changed files with 41 additions and 18 deletions

View File

@ -21,7 +21,7 @@
<div class="form-group">
<label for="isin">isin</label>
<input
type="isin"
type="text"
class="form-control"
name="isin"
[(ngModel)]="data.isin"
@ -45,7 +45,7 @@
<div class="form-group">
<label for="count">Count</label>
<input
type="count"
type="number"
class="form-control"
name="count"
[(ngModel)]="data.count"
@ -53,6 +53,9 @@
count
#count="ngModel"
/>
<div class="alert-danger" *ngIf="!countValid">
Password does not match, make sure it is the same!
</div>
</div>
<div class="form-group">
<label for="price">Price in $</label>
@ -64,6 +67,9 @@
#price="ngModel"
type="number"
/>
<div class="alert-danger" *ngIf="!priceValid">
Password does not match, make sure it is the same!
</div>
</div>
<div class="form-group footer-buttons">
<button class="btn btn-danger btn-block" mat-dialog-close>Cancel</button>

View File

@ -1,4 +1,5 @@
import { Component, Inject, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import {
MatDialog,
MatDialogRef,
@ -21,21 +22,37 @@ export class UserDialogComponent {
@Inject(MAT_DIALOG_DATA) public data: TransactionData
) {}
countValid = true;
priceValid = true;
onSubmit() {
//TODO check that price is decimal
console.log(
this.dataService
.createTransaction(
this.data.comment,
this.data.isin,
this.data.time,
+this.data.count,
+this.data.price.toFixed(2) * -1
)
.subscribe((data) => {
console.log(data);
})
);
this.dialog.closeAll();
console.log(!isNaN(this.data.count));
if (!isNaN(this.data.count) && !isNaN(this.data.price)) {
this.priceValid = true;
this.countValid = true;
console.log(
this.dataService
.createTransaction(
this.data.comment,
this.data.isin,
this.data.time,
+this.data.count,
+this.data.price.toFixed(2) * -1
)
.subscribe((data) => {
console.log(data);
})
);
this.dialog.closeAll();
} else if (isNaN(this.data.count) && !isNaN(this.data.price)) {
this.priceValid = true;
this.countValid = false;
} else if (!isNaN(this.data.count) && isNaN(this.data.price)) {
this.priceValid = false;
this.countValid = true;
} else {
this.countValid = false;
this.priceValid = false;
}
}
}

View File

@ -111,7 +111,7 @@
<mat-form-field class="example-full-width" appearance="fill">
<mat-label>Telegram UserId</mat-label>
<input
type="text"
type="number"
matInput
[formControl]="telegramIdFormControl"
[(ngModel)]="userId"