From 92ae370111ad73cc8e8f1f3232ccd00cf4f0148c Mon Sep 17 00:00:00 2001 From: Lucchetto Date: Wed, 12 May 2021 12:34:13 +0200 Subject: [PATCH 1/2] Allow toggling valid classes Signed-off-by: Lucchetto --- .../lib/Components/form-group/form-group.component.ts | 2 +- .../src/lib/Directives/form-control.directive.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/projects/ng-bootstrap-form-validation/src/lib/Components/form-group/form-group.component.ts b/projects/ng-bootstrap-form-validation/src/lib/Components/form-group/form-group.component.ts index 653a684..d187bcb 100644 --- a/projects/ng-bootstrap-form-validation/src/lib/Components/form-group/form-group.component.ts +++ b/projects/ng-bootstrap-form-validation/src/lib/Components/form-group/form-group.component.ts @@ -23,7 +23,7 @@ import { ErrorMessage } from "../../Models/error-message"; ` }) export class FormGroupComponent implements OnInit, AfterContentInit { - @ContentChildren(FormControlName, {descendants: true}) + @ContentChildren(FormControlName, { descendants: true }) FormControlNames: QueryList; @Input() diff --git a/projects/ng-bootstrap-form-validation/src/lib/Directives/form-control.directive.ts b/projects/ng-bootstrap-form-validation/src/lib/Directives/form-control.directive.ts index db9ddba..f274df9 100644 --- a/projects/ng-bootstrap-form-validation/src/lib/Directives/form-control.directive.ts +++ b/projects/ng-bootstrap-form-validation/src/lib/Directives/form-control.directive.ts @@ -25,13 +25,20 @@ export class FormControlDirective { formControlName: string; @Input() formControl: string; + @Input() + showValid = true; + @Input() + showValidWhenEmpty = true; @HostBinding("class.is-valid") get validClass() { - if (!this.control) { + if (!this.control || !this.showValid) { return false; } return ( + (this.showValidWhenEmpty + ? true + : this.control.value != null && this.control.value != "") && this.bootstrapFour && this.control.valid && (this.control.touched || this.control.dirty) From 71d86b3ca5ef2061eade749640b45c3a4a3ed623 Mon Sep 17 00:00:00 2001 From: Lucchetto Date: Sat, 22 May 2021 18:16:03 +0200 Subject: [PATCH 2/2] Don't show valid state on empty by default Signed-off-by: Lucchetto --- .../src/lib/Directives/form-control.directive.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/projects/ng-bootstrap-form-validation/src/lib/Directives/form-control.directive.ts b/projects/ng-bootstrap-form-validation/src/lib/Directives/form-control.directive.ts index f274df9..845673d 100644 --- a/projects/ng-bootstrap-form-validation/src/lib/Directives/form-control.directive.ts +++ b/projects/ng-bootstrap-form-validation/src/lib/Directives/form-control.directive.ts @@ -1,3 +1,9 @@ +/* + * @Author: Zhenxiang Chen + * @Date: 2021-05-22 18:15:39 + * @Last Modified by: Zhenxiang Chen + * @Last Modified time: 2021-05-22 18:15:39 + */ import { Directive, Input, @@ -28,7 +34,7 @@ export class FormControlDirective { @Input() showValid = true; @Input() - showValidWhenEmpty = true; + showValidWhenEmpty = false; @HostBinding("class.is-valid") get validClass() {