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"> <div class="form-group">
<label for="isin">isin</label> <label for="isin">isin</label>
<input <input
type="isin" type="text"
class="form-control" class="form-control"
name="isin" name="isin"
[(ngModel)]="data.isin" [(ngModel)]="data.isin"
@ -45,7 +45,7 @@
<div class="form-group"> <div class="form-group">
<label for="count">Count</label> <label for="count">Count</label>
<input <input
type="count" type="number"
class="form-control" class="form-control"
name="count" name="count"
[(ngModel)]="data.count" [(ngModel)]="data.count"
@ -53,6 +53,9 @@
count count
#count="ngModel" #count="ngModel"
/> />
<div class="alert-danger" *ngIf="!countValid">
Password does not match, make sure it is the same!
</div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="price">Price in $</label> <label for="price">Price in $</label>
@ -64,6 +67,9 @@
#price="ngModel" #price="ngModel"
type="number" type="number"
/> />
<div class="alert-danger" *ngIf="!priceValid">
Password does not match, make sure it is the same!
</div>
</div> </div>
<div class="form-group footer-buttons"> <div class="form-group footer-buttons">
<button class="btn btn-danger btn-block" mat-dialog-close>Cancel</button> <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 { Component, Inject, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import { import {
MatDialog, MatDialog,
MatDialogRef, MatDialogRef,
@ -21,21 +22,37 @@ export class UserDialogComponent {
@Inject(MAT_DIALOG_DATA) public data: TransactionData @Inject(MAT_DIALOG_DATA) public data: TransactionData
) {} ) {}
countValid = true;
priceValid = true;
onSubmit() { onSubmit() {
//TODO check that price is decimal console.log(!isNaN(this.data.count));
console.log( if (!isNaN(this.data.count) && !isNaN(this.data.price)) {
this.dataService this.priceValid = true;
.createTransaction( this.countValid = true;
this.data.comment, console.log(
this.data.isin, this.dataService
this.data.time, .createTransaction(
+this.data.count, this.data.comment,
+this.data.price.toFixed(2) * -1 this.data.isin,
) this.data.time,
.subscribe((data) => { +this.data.count,
console.log(data); +this.data.price.toFixed(2) * -1
}) )
); .subscribe((data) => {
this.dialog.closeAll(); 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-form-field class="example-full-width" appearance="fill">
<mat-label>Telegram UserId</mat-label> <mat-label>Telegram UserId</mat-label>
<input <input
type="text" type="number"
matInput matInput
[formControl]="telegramIdFormControl" [formControl]="telegramIdFormControl"
[(ngModel)]="userId" [(ngModel)]="userId"