Skip to content

Commit

Permalink
fix(module:form): fix form control validate with formControl
Browse files Browse the repository at this point in the history
  • Loading branch information
vthinkxie authored and Ricbet committed Apr 9, 2020
1 parent 81b9ff8 commit 8adac34
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions components/form/nz-form-control.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
TemplateRef,
ViewEncapsulation
} from '@angular/core';
import { FormControl, FormControlName, NgControl, NgModel } from '@angular/forms';
import { FormControl, FormControlDirective, FormControlName, NgControl, NgModel } from '@angular/forms';
import { Subscription } from 'rxjs';
import { startWith } from 'rxjs/operators';

Expand Down Expand Up @@ -59,7 +59,7 @@ export class NzFormControlComponent extends NzColDirective
status: NzFormControlStatusType = null;
controlClassMap: NgClassType = {};
iconType: string;
@ContentChild(NgControl, { static: false }) defaultValidateControl: FormControlName;
@ContentChild(NgControl, { static: false }) defaultValidateControl: FormControlName | FormControlDirective;
@Input() nzSuccessTip: string | TemplateRef<{ $implicit: FormControl | NgModel }>;
@Input() nzWarningTip: string | TemplateRef<{ $implicit: FormControl | NgModel }>;
@Input() nzErrorTip: string | TemplateRef<{ $implicit: FormControl | NgModel }>;
Expand Down Expand Up @@ -194,8 +194,12 @@ export class NzFormControlComponent extends NzColDirective
}

ngAfterContentInit(): void {
if (this.defaultValidateControl && !this.validateControl && !this.validateString) {
this.nzValidateStatus = this.defaultValidateControl;
if (!this.validateControl && !this.validateString) {
if (this.defaultValidateControl instanceof FormControlDirective) {
this.nzValidateStatus = this.defaultValidateControl.control;
} else {
this.nzValidateStatus = this.defaultValidateControl;
}
}
}

Expand Down

0 comments on commit 8adac34

Please sign in to comment.