Skip to content

Commit aca336a

Browse files
author
fengtianze
committedFeb 20, 2021
fix: support dynamic hints and errors rendering
1 parent 879de89 commit aca336a

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed
 

‎src/form/__snapshots__/form.component.spec.ts.snap

-12
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,6 @@ exports[`FormComponent should match snapshot 2`] = `
124124
</div>
125125
</div>
126126
127-
<div
128-
class="aui-form-item__error-wrapper"
129-
>
130-
131-
<div
132-
auiformitemerror=""
133-
class="aui-form-item__error"
134-
>
135-
required
136-
</div>
137-
138-
</div>
139127
140128
<div
141129
class="aui-form-item__hint-wrapper"

‎src/form/form-item/form-item.component.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
</div>
2424
</div>
2525
<div
26-
*ngIf="(hasError$ | async) && errors?.length"
26+
*ngIf="(hasError$ | async) && (errorCount$ | async)"
2727
class="aui-form-item__error-wrapper"
2828
>
2929
<ng-content select="[auiFormItemError]"></ng-content>
3030
</div>
31-
<div *ngIf="hints?.length" class="aui-form-item__hint-wrapper">
31+
<div *ngIf="hintCount$ | async" class="aui-form-item__hint-wrapper">
3232
<ng-content select="[auiFormItemHint]"></ng-content>
3333
</div>
3434
</div>

‎src/form/form-item/form-item.component.ts

+12
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ export class FormItemComponent implements AfterContentInit, OnDestroy {
7272
hints: QueryList<FormItemHintDirective>;
7373

7474
hasError$: Observable<boolean>;
75+
errorCount$: Observable<number>;
76+
hintCount$: Observable<number>;
7577
parentForm: NgForm | FormGroupDirective;
7678

7779
private readonly destroy$$ = new Subject<void>();
@@ -97,6 +99,16 @@ export class FormItemComponent implements AfterContentInit, OnDestroy {
9799
).pipe(map(statuses => statuses.some(status => status))),
98100
),
99101
);
102+
103+
this.errorCount$ = this.errors.changes.pipe(
104+
map(errors => errors.length),
105+
startWith(this.errors.length),
106+
);
107+
108+
this.hintCount$ = this.hints.changes.pipe(
109+
map(hints => hints.length),
110+
startWith(this.hints.length),
111+
);
100112
}
101113

102114
subscribeInputsFromParent() {

0 commit comments

Comments
 (0)
Please sign in to comment.