Skip to content

Commit 14a7388

Browse files
authoredOct 14, 2022
fix(form): fix missing error style (#1537)
1 parent a4e62ef commit 14a7388

8 files changed

+25
-25
lines changed
 

‎CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## [14.1.0](https://github.com/ng-alain/delon/compare/14.0.0...14.0.1) (2022-10-09)
1+
## [14.1.0](https://github.com/ng-alain/delon/compare/14.0.0...14.1.0) (2022-10-09)
22

33

44
### Bug Fixes

‎packages/form/spec/form.spec.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -527,12 +527,8 @@ describe('form: component', () => {
527527
const namePath = '/name';
528528
context.comp.updateFeedback(namePath, 'error');
529529
page.dc().checkCount('.ant-form-item-has-error', 1).checkCount('.ant-form-item-has-feedback', 1);
530-
context.comp.updateFeedback(namePath, 'success', 'left');
531-
page
532-
.dc()
533-
.checkCount('.ant-form-item-has-success', 1)
534-
.checkCount('.ant-form-item-has-feedback', 1)
535-
.checkCount('.anticon-left', 1);
530+
context.comp.updateFeedback(namePath, 'success');
531+
page.dc().checkCount('.ant-form-item-has-success', 1).checkCount('.ant-form-item-has-feedback', 1);
536532
context.comp.updateFeedback(namePath);
537533

538534
page.dc().checkCount('.ant-form-item-has-feedback', 0);

‎packages/form/src/errors.ts

+3
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,8 @@ export interface ErrorSchema {
110110
*/
111111
feedback?: NzFormControlStatusType;
112112

113+
/**
114+
* @deprecated Will be removed of NG-ZORRO don't support
115+
*/
113116
feedbackIcon?: string | null;
114117
}

‎packages/form/src/model/form.property.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BehaviorSubject, combineLatest, Observable, distinctUntilChanged, map } from 'rxjs';
22

33
import { AlainSFConfig } from '@delon/util/config';
4+
import { NzFormStatusService } from 'ng-zorro-antd/core/form';
45
import type { NzSafeAny } from 'ng-zorro-antd/core/types';
56
import type { NzFormControlStatusType } from 'ng-zorro-antd/form';
67

@@ -373,17 +374,9 @@ export abstract class FormProperty {
373374

374375
// #endregion
375376

376-
updateFeedback(status: NzFormControlStatusType = '', icon?: string | null): void {
377+
updateFeedback(status: NzFormControlStatusType = ''): void {
377378
this.ui.feedback = status;
378-
this.ui.feedbackIcon =
379-
icon ||
380-
{
381-
'': '',
382-
error: 'close-circle-fill',
383-
validating: 'loading',
384-
success: 'check-circle-fill',
385-
warning: 'exclamation-circle-fill'
386-
}[status];
379+
this.widget.injector.get(NzFormStatusService).formStatusChanges.next({ status, hasFeedback: !!status });
387380
this.widget.detectChanges();
388381
}
389382
}

‎packages/form/src/sf-item-wrap.component.html

-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
<div class="ant-form-item-control-input-content">
3636
<ng-content></ng-content>
3737
</div>
38-
<span class="ant-form-item-children-icon">
39-
<i *ngIf="ui.feedbackIcon" nz-icon [nzType]="ui.feedbackIcon"></i>
40-
</span>
4138
</div>
4239
<div *ngIf="!ui.onlyVisual && showError" @helpMotion class="ant-form-item-explain ant-form-item-explain-connected">
4340
<div role="alert" class="ant-form-item-explain-error">

‎packages/form/src/sf-item-wrap.component.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Component, Input, ViewEncapsulation } from '@angular/core';
1+
import { Component, Input, OnChanges, ViewEncapsulation } from '@angular/core';
22

33
import { helpMotion } from 'ng-zorro-antd/core/animation';
4+
import { NzFormStatusService } from 'ng-zorro-antd/core/form';
45

56
import type { SFSchema } from './schema/index';
67
import type { SFOptionalHelp, SFUISchemaItem } from './schema/ui';
@@ -12,7 +13,7 @@ import type { SFOptionalHelp, SFUISchemaItem } from './schema/ui';
1213
preserveWhitespaces: false,
1314
encapsulation: ViewEncapsulation.None
1415
})
15-
export class SFItemWrapComponent {
16+
export class SFItemWrapComponent implements OnChanges {
1617
_showTitle: boolean = false;
1718
@Input() id?: string;
1819
@Input() schema!: SFSchema;
@@ -32,4 +33,11 @@ export class SFItemWrapComponent {
3233
get oh(): SFOptionalHelp {
3334
return this.ui.optionalHelp as SFOptionalHelp;
3435
}
36+
37+
constructor(private statusSrv: NzFormStatusService) {}
38+
39+
ngOnChanges(): void {
40+
const hasError = !!this.error;
41+
this.statusSrv.formStatusChanges.next({ status: hasError ? 'error' : '', hasFeedback: hasError });
42+
}
3543
}

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
} from '@angular/core';
1313
import { Subject } from 'rxjs';
1414

15+
import { NzFormStatusService } from 'ng-zorro-antd/core/form';
16+
1517
import { FormProperty } from './model/form.property';
1618
import { SFUISchemaItem } from './schema/ui';
1719
import { TerminatorService } from './terminator.service';
@@ -29,7 +31,8 @@ let nextUniqueId = 0;
2931
<ng-container *ngTemplateOutlet="footer"></ng-container>
3032
`,
3133
preserveWhitespaces: false,
32-
encapsulation: ViewEncapsulation.None
34+
encapsulation: ViewEncapsulation.None,
35+
providers: [NzFormStatusService]
3336
})
3437
export class SFItemComponent implements OnInit, OnChanges, OnDestroy {
3538
private ref!: ComponentRef<Widget<FormProperty, SFUISchemaItem>>;

‎packages/form/src/sf.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ export class SFComponent implements OnInit, OnChanges, OnDestroy {
236236
* this.sf.updateFeedback('/name');
237237
* ```
238238
*/
239-
updateFeedback(path: string, status: NzFormControlStatusType = '', icon?: string | null): this {
240-
this.getProperty(path)?.updateFeedback(status, icon);
239+
updateFeedback(path: string, status: NzFormControlStatusType = ''): this {
240+
this.getProperty(path)?.updateFeedback(status);
241241
return this;
242242
}
243243

0 commit comments

Comments
 (0)
Please sign in to comment.