From 52d79f04497e3f65121f1ab642332ba2b4263a55 Mon Sep 17 00:00:00 2001 From: ickisIckis Date: Tue, 20 Aug 2024 19:59:08 +0300 Subject: [PATCH 1/3] fix(components/input-layout-date): min max should correction for manual input #000 --- .../input-layout-date-base-example.component.html | 8 +++++++- .../input-layout-date-base-example.component.ts | 3 +++ .../input/input-date/input-layout-date.component.ts | 13 ++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/apps/doc/src/app/components/input/input-layout-date/examples/base/input-layout-date-base-example.component.html b/apps/doc/src/app/components/input/input-layout-date/examples/base/input-layout-date-base-example.component.html index bcc763ca2d..bba34b5ba7 100644 --- a/apps/doc/src/app/components/input/input-layout-date/examples/base/input-layout-date-base-example.component.html +++ b/apps/doc/src/app/components/input/input-layout-date/examples/base/input-layout-date-base-example.component.html @@ -1,3 +1,9 @@ - + + +
+  min: {{ min.toLocalNativeDate() | date : 'shortDate' }}
+  max: {{ max.toLocalNativeDate() | date : 'shortDate' }}
+  value: {{ control.value }}
+
diff --git a/apps/doc/src/app/components/input/input-layout-date/examples/base/input-layout-date-base-example.component.ts b/apps/doc/src/app/components/input/input-layout-date/examples/base/input-layout-date-base-example.component.ts index 9f5b35d0ef..bdc2470a74 100644 --- a/apps/doc/src/app/components/input/input-layout-date/examples/base/input-layout-date-base-example.component.ts +++ b/apps/doc/src/app/components/input/input-layout-date/examples/base/input-layout-date-base-example.component.ts @@ -16,4 +16,7 @@ import { PrizmDay } from '@prizm-ui/components'; }) export class PrizmInputLayoutDateBaseExampleComponent { public readonly control = new UntypedFormControl(new PrizmDay(2017, 0, 15)); + readonly min = new PrizmDay(2000, 2, 20); + + readonly max = new PrizmDay(2040, 2, 20); } diff --git a/libs/components/src/lib/components/input/input-date/input-layout-date.component.ts b/libs/components/src/lib/components/input/input-date/input-layout-date.component.ts index 2dd728dda6..df09d67cde 100644 --- a/libs/components/src/lib/components/input/input-date/input-layout-date.component.ts +++ b/libs/components/src/lib/components/input/input-date/input-layout-date.component.ts @@ -198,7 +198,7 @@ export class PrizmInputLayoutDateComponent extends PrizmInputNgControl Date: Wed, 21 Aug 2024 12:03:34 +0300 Subject: [PATCH 2/3] fix(components/input-layput-date): progress for min max correction #000 --- .../common/base/input-ng-control.class.ts | 8 +++---- .../input-layout-date.component.html | 1 + .../input-date/input-layout-date.component.ts | 24 ++++++++++++++++++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/libs/components/src/lib/components/input/common/base/input-ng-control.class.ts b/libs/components/src/lib/components/input/common/base/input-ng-control.class.ts index 48b1ff68ae..712634679f 100644 --- a/libs/components/src/lib/components/input/common/base/input-ng-control.class.ts +++ b/libs/components/src/lib/components/input/common/base/input-ng-control.class.ts @@ -18,7 +18,7 @@ export abstract class PrizmInputNgControl ngControl!: NgControl; readonly changeDetectorRef!: ChangeDetectorRef; readonly layoutComponent?: PrizmInputLayoutComponent | null; - private previousInternalValue$$ = new BehaviorSubject(null); + protected previousInternalValue$$ = new BehaviorSubject(null); onChange: (val: T) => void = PRIZM_EMPTY_FUNCTION; onTouch: () => void = PRIZM_EMPTY_FUNCTION; protected readonly focusableElement?: ElementRef | any; @@ -118,9 +118,9 @@ export abstract class PrizmInputNgControl } protected updateValue(value: T): void { - if (this.disabled || this.valueIdenticalComparator(this.value, value)) { - return; - } + // if (this.disabled || this.valueIdenticalComparator(this.value, value)) { + // return; + // } this.onChange(value); this.previousInternalValue$$.next(value); this.controlSetValue(value); diff --git a/libs/components/src/lib/components/input/input-date/input-layout-date.component.html b/libs/components/src/lib/components/input/input-date/input-layout-date.component.html index b5fd0eafbb..6e554fb93c 100644 --- a/libs/components/src/lib/components/input/input-date/input-layout-date.component.html +++ b/libs/components/src/lib/components/input/input-date/input-layout-date.component.html @@ -11,6 +11,7 @@ ; + @ViewChild('mask', { read: NgxMaskDirective }) + public textMask?: NgxMaskDirective; + private month: PrizmMonth | null = null; public mask = prizmCreateDateNgxMask(this.dateFormat, this.dateSeparator); @@ -146,6 +152,7 @@ export class PrizmInputLayoutDateComponent extends PrizmInputNgControl; private readonly iconsFullRegistry = inject(PrizmIconsFullRegistry); + private readonly render2 = inject(Renderer2); constructor( @Inject(Injector) injector: Injector, @@ -164,6 +171,18 @@ export class PrizmInputLayoutDateComponent extends PrizmInputNgControl { + if (this.focusableElement?.nativeElement && !this.focused) { + console.log(this.previousInternalValue$$.value, 1111111111); + this.render2.setProperty( + this.focusableElement.nativeElement, + 'value', + this.previousInternalValue$$.value ?? '' + ); + this.textMask?.writeValue(this.previousInternalValue$$.value ?? ''); + } + }); } public override ngOnInit(): void { @@ -220,6 +239,9 @@ export class PrizmInputLayoutDateComponent extends PrizmInputNgControl Date: Wed, 21 Aug 2024 13:38:13 +0300 Subject: [PATCH 3/3] fix(components/input-date): update value for mask #000 --- .../input/common/base/input-ng-control.class.ts | 13 +++++++++---- .../input-date/input-layout-date.component.html | 1 - .../input/input-date/input-layout-date.component.ts | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/libs/components/src/lib/components/input/common/base/input-ng-control.class.ts b/libs/components/src/lib/components/input/common/base/input-ng-control.class.ts index 712634679f..a2393b9c78 100644 --- a/libs/components/src/lib/components/input/common/base/input-ng-control.class.ts +++ b/libs/components/src/lib/components/input/common/base/input-ng-control.class.ts @@ -1,4 +1,4 @@ -import { ChangeDetectorRef, Directive, ElementRef, inject, Injector, OnInit } from '@angular/core'; +import { ChangeDetectorRef, Directive, ElementRef, inject, Injector, OnInit, Renderer2 } from '@angular/core'; import { AbstractControl, ControlValueAccessor, NgControl, NgModel, Validators } from '@angular/forms'; import { PrizmInputControl } from './input-control.class'; import { PrizmDestroyService } from '@prizm-ui/helpers'; @@ -74,6 +74,7 @@ export abstract class PrizmInputNgControl return !!this.ngControl?.touched; } + public readonly renderer2 = inject(Renderer2); protected constructor( protected readonly injector: Injector, readonly valueTransformer?: PrizmControlValueTransformer | null @@ -118,9 +119,9 @@ export abstract class PrizmInputNgControl } protected updateValue(value: T): void { - // if (this.disabled || this.valueIdenticalComparator(this.value, value)) { - // return; - // } + if (this.disabled /*|| this.valueIdenticalComparator(this.value, value)*/) { + return; + } this.onChange(value); this.previousInternalValue$$.next(value); this.controlSetValue(value); @@ -131,6 +132,10 @@ export abstract class PrizmInputNgControl } public setDisabledState(isDisabled: boolean) { + if (this.focusableElement?.nativeElement) { + this.renderer2.setProperty(this.focusableElement.nativeElement, 'disabled', isDisabled); + } + this.checkControlUpdate(); this.stateChanges.next(); } diff --git a/libs/components/src/lib/components/input/input-date/input-layout-date.component.html b/libs/components/src/lib/components/input/input-date/input-layout-date.component.html index 6e554fb93c..6394ec1d39 100644 --- a/libs/components/src/lib/components/input/input-date/input-layout-date.component.html +++ b/libs/components/src/lib/components/input/input-date/input-layout-date.component.html @@ -16,7 +16,6 @@ [showMaskTyped]="focusableElementRef.focused" [dropSpecialCharacters]="false" [placeholder]="placeholder" - [disabled]="!!disabled" [ngModelOptions]="{ standalone: true }" [ngModel]="stringValue" (ngModelChange)="onValueChange($event || '')" diff --git a/libs/components/src/lib/components/input/input-date/input-layout-date.component.ts b/libs/components/src/lib/components/input/input-date/input-layout-date.component.ts index a30e3d00d9..66bc454e13 100644 --- a/libs/components/src/lib/components/input/input-date/input-layout-date.component.ts +++ b/libs/components/src/lib/components/input/input-date/input-layout-date.component.ts @@ -172,15 +172,15 @@ export class PrizmInputLayoutDateComponent extends PrizmInputNgControl { if (this.focusableElement?.nativeElement && !this.focused) { - console.log(this.previousInternalValue$$.value, 1111111111); this.render2.setProperty( this.focusableElement.nativeElement, 'value', this.previousInternalValue$$.value ?? '' ); - this.textMask?.writeValue(this.previousInternalValue$$.value ?? ''); + this.textMask?.writeValue(this.previousInternalValue$$.value?.toString() ?? ''); } }); }