如果验证错误,如何禁用按钮

时间:2019-01-04 06:12:37

标签: angular typescript

我有一个表数据,在继续下一步之前,我需要验证一些东西,例如应选择一行作为键行,输入,时间和段行。 我编写了这样的代码,以便在用户未选择键,时间,行和分段之前,下一个按钮保持禁用状态。 但是我的问题是,如果用户选择行作为键,时间等,并且启用了``下一步''按钮然后取消选择它,即使启用了``下一步''按钮。如果用户取消选择行类型,我希望将其禁用(行类型表示键,输入,细分等)。

// Code for Validation of Key and Segment
KeyTimeValidation(event, element) {
if (event.value == 'Key' || event.value == 'Time') {
  let val = this.columnList.filter(column => column.type == event.value)
  if (val.length > 1) {
    this.columnList.forEach(column => {
      if (column.columnName === element.columnName) {
        column.type = 'None';
        this.snakbar.statusBar(event.value + ' type cannot be more than one', 'Info');
      }
    })
  }
 const json = JSON.stringify(this.columnList);
  this.columnList = [];
  this.columnList = JSON.parse(json);
  this.dataSource = new MatTableDataSource<any>(this.columnList);

  this.dataSource
    .connect()
    .subscribe(list => this.columnListChange.emit(list));

}
let key = this.columnList.filter(column => column.type == 'Key' && column.selected == true);
let time = this.columnList.filter(column => column.type == 'Time' && column.selected == true);
let segment = this.columnList.filter(column => column.type == 'Segment' && column.selected == true);
let quantile = this.columnList.filter(column => column.type == 'Quantile' && column.selected == true);
let input = this.columnList.filter(column => column.type == 'Input' && column.selected == true);
if (key.length >= 1 && time.length >= 1 && (input.length != 0 && (segment.length != 0 || quantile.length != 0))) {
  this.validateSegInput = true;
}
else {
  this.validateSegInput = false;
}

}

我在html中禁用了代码

 <mat-toolbar>
              <button mat-raised-button color="view-data" [disabled]="!validateSegInput" matTooltip="Save Metadata"
                (click)="saveMetadata()" type="button">
                Save
              </button>
              <button color="primary" [disabled]="!validateSegInput" (click)="saveSampleData()" mat-raised-button>
                Next</button>

            </mat-toolbar>
                                                                          What i want is that once the button gets enabled it should get disabled it the condition are false

0 个答案:

没有答案