Skip to content

Commit

Permalink
fix(module:form): fix form feedback error when init with tips (#3868)
Browse files Browse the repository at this point in the history
close #3865
  • Loading branch information
vthinkxie committed Jul 26, 2019
1 parent c4de8ff commit 7c0aa51
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion components/form/nz-form-control.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class NzFormControlComponent extends NzColDirective
this.iconType = '';
}
if (this.hasTips) {
this.nzFormItemComponent.withHelpClass = this.showInnerTip;
this.nzFormItemComponent.setWithHelpViaTips(this.showErrorTip);
}
this.controlClassMap = {
[`has-warning`]: this.status === 'warning',
Expand Down
27 changes: 18 additions & 9 deletions components/form/nz-form-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class NzFormItemComponent extends NzRowDirective
@ContentChildren(NzFormExplainComponent, { descendants: true })
listOfNzFormExplainComponent: QueryList<NzFormExplainComponent>;
withHelpClass = false;
tipsMode = false;

updateFlexStyle(): void {
if (this.nzFlex) {
Expand All @@ -67,6 +68,12 @@ export class NzFormItemComponent extends NzRowDirective
}
}

setWithHelpViaTips(value: boolean): void {
this.tipsMode = true;
this.withHelpClass = value;
this.cdr.markForCheck();
}

constructor(
elementRef: ElementRef,
renderer: Renderer2,
Expand All @@ -82,15 +89,17 @@ export class NzFormItemComponent extends NzRowDirective
}

ngAfterContentInit(): void {
this.listOfNzFormExplainComponent.changes
.pipe(
startWith(true),
takeUntil(this.destroy$)
)
.subscribe(() => {
this.withHelpClass = this.listOfNzFormExplainComponent && this.listOfNzFormExplainComponent.length > 0;
this.cdr.markForCheck();
});
if (!this.tipsMode) {
this.listOfNzFormExplainComponent.changes
.pipe(
startWith(true),
takeUntil(this.destroy$)
)
.subscribe(() => {
this.withHelpClass = this.listOfNzFormExplainComponent && this.listOfNzFormExplainComponent.length > 0;
this.cdr.markForCheck();
});
}
}

ngOnInit(): void {
Expand Down

0 comments on commit 7c0aa51

Please sign in to comment.