Fix validation

pull/6/head
Max Ehrlicher-Schmidt 4 years ago
parent 47086c3c35
commit 2f872c84a5

@ -4,12 +4,10 @@ import {
Input, Input,
Output, Output,
EventEmitter, EventEmitter,
ChangeDetectionStrategy,
ViewChild, ViewChild,
ChangeDetectorRef, ChangeDetectorRef,
AfterViewInit, AfterViewInit,
} from '@angular/core'; } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
@Component({ @Component({
selector: 'app-cell', selector: 'app-cell',
@ -33,6 +31,10 @@ export class CellComponent implements AfterViewInit {
@Input() @Input()
set editable(value: boolean) { set editable(value: boolean) {
this._editable = value; this._editable = value;
if (value) {
this.input?.control?.markAsTouched();
this.checkIfValid();
}
} }
get editable(): boolean { get editable(): boolean {
return this._editable; return this._editable;
@ -82,10 +84,7 @@ export class CellComponent implements AfterViewInit {
this.checkIfValid(); this.checkIfValid();
this.cdr.detectChanges(); this.cdr.detectChanges();
if ( if (this.inputType === 'Boolean' && this.editable) {
this.inputType === 'Boolean' &&
this.editable
) {
setTimeout(() => { setTimeout(() => {
this.change(false); this.change(false);
}); });
@ -143,9 +142,11 @@ export class CellComponent implements AfterViewInit {
} }
checkIfValid() { checkIfValid() {
if (this.required && this.inputType !== 'Boolean') { setTimeout(() => {
if (this.editable && this.required && this.inputType !== 'Boolean') {
this.isValid = this.input?.control?.valid || false; this.isValid = this.input?.control?.valid || false;
this.validityChange.emit(this.isValid); this.validityChange.emit(this.isValid);
} }
});
} }
} }

Loading…
Cancel
Save