fixed error message on command modal shows everytime

This commit is contained in:
Yubing325 2020-11-02 09:56:19 -06:00
parent 565d41c329
commit fbcd9fa568
3 changed files with 20 additions and 32 deletions

View File

@ -7,7 +7,7 @@
<div class="modal-body"> <div class="modal-body">
<ng-container [ngTemplateOutlet]="template" <ng-container [ngTemplateOutlet]="template"
[ngTemplateOutletContext]="{ $implicit: commandModel, loading: loading }"></ng-container> [ngTemplateOutletContext]="{ $implicit: commandModel, loading: loading }"></ng-container>
<div *ngIf="validationMessage" class="alert alert-danger mt-2" style="white-space: pre-wrap">{{validationMessage}}</div> <div *ngIf="hasError" class="alert alert-danger mt-2" style="white-space: pre-wrap">{{validationMessage}}</div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-light" (click)="modalRef.hide()" <button type="button" class="btn btn-light" (click)="modalRef.hide()"

View File

@ -25,6 +25,7 @@ export class CommandModalComponent implements OnInit, OnDestroy {
validationMessage:string ; validationMessage:string ;
btnClass:string; btnClass:string;
successEmitter: EventEmitter<any>; successEmitter: EventEmitter<any>;
hasError: boolean;
private _notifyMessage: Subscription; private _notifyMessage: Subscription;
private _validationError: Subscription; private _validationError: Subscription;
@ -53,8 +54,6 @@ export class CommandModalComponent implements OnInit, OnDestroy {
} }
onSubmit(){ onSubmit(){
this.loading = true; this.loading = true;
this.validationMessage = null; this.validationMessage = null;
@ -67,10 +66,11 @@ export class CommandModalComponent implements OnInit, OnDestroy {
.subscribe(commandResult => { .subscribe(commandResult => {
if (this.refreshOnSuccess) if (this.refreshOnSuccess)
this.dataSource.refresh(); this.dataSource.refresh();
this.hasError = false;
this.modalRef.hide(); this.modalRef.hide();
this.successEmitter.emit(commandResult); this.successEmitter.emit(commandResult);
}, fail => { }, fail => {
this.hasError = true;
// you do not want to close on failure.. so just ignore.. // you do not want to close on failure.. so just ignore..
}); });
} }

View File

@ -55,18 +55,10 @@
<button class="btn-info btn" psbxCommandModal [commandTitle]="'Change ' + model.name + ' name'" <button class="btn-info btn" psbxCommandModal [commandTitle]="'Change ' + model.name + ' name'"
commandText="Update" [dataSource]="merchantDataSource" command="changeMerchant" [model]="model" commandText="Update" [dataSource]="merchantDataSource" command="changeMerchant" [model]="model"
[template]="theModal">Change</button> [template]="theModal">Change</button>
<button class="btn-danger btn" <button class="btn-danger btn" psbxCommand [dataSource]="merchantDataSource" command="removeMerchant"
psbxCommand [model]="model" [confirm]="true" yesClass="warning" noClass="secondary" noText="Cancel Delete"
[dataSource]="merchantDataSource"
command="removeMerchant"
[model]="model"
[confirm]="true"
yesClass="warning"
noClass = "secondary"
noText = "Cancel Delete"
yesText="Delete It" yesText="Delete It"
confirmMessage="Are you sure you want to delete this merchant?" confirmMessage="Are you sure you want to delete this merchant?">RemoveIt</button></div>
>RemoveIt</button></div>
</ng-container> </ng-container>
</ng-container> </ng-container>
@ -78,17 +70,16 @@
<ng-template #theModal let-command let-loading="loading"> <ng-template #theModal let-command let-loading="loading">
<label for="name">Name</label> <label for="name">Name</label>
<input type="text" required [(ngModel)]="command.name" placeholder="Enter a merchant name" <input type="text" required [(ngModel)]="command.name" placeholder="Enter a merchant name" class="form-control">
class="form-control">
<label for="address">Address</label> <label for="address">Address</label>
<input type="text" required [(ngModel)]="command.address" <input type="text" required [(ngModel)]="command.address" placeholder="Enter the merchant's address"
placeholder="Enter the merchant's address" class="form-control"> class="form-control">
<label for="address">Priority</label> <label for="address">Priority</label>
<input type="number" required [(ngModel)]="command.ordering" <input type="number" required [(ngModel)]="command.ordering" placeholder="Enter the merchant's Priority"
placeholder="Enter the merchant's Priority" class="form-control"> class="form-control">
<label for="address">Priority</label> <label for="address">Priority</label>
<input type="date" required [(ngModel)]="command.openDate" <input type="date" required [(ngModel)]="command.openDate" placeholder="Enter the merchant's Priority"
placeholder="Enter the merchant's Priority" class="form-control"> class="form-control">
</ng-template> </ng-template>
@ -100,6 +91,3 @@
<button type="button" class="btn btn-primary">No</button> <button type="button" class="btn btn-primary">No</button>
</div> </div>
</ng-template> </ng-template>