From 079cd67a2d049c2cd4d5721e6beba329ca3a2e68 Mon Sep 17 00:00:00 2001 From: Giannin Date: Thu, 14 Nov 2024 15:09:15 +0100 Subject: [PATCH] Implement setDisabledState method in new MetricCheckInDirective --- .../check-in-form-metric/MetricCheckInDirective.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/components/checkin/check-in-form-metric/MetricCheckInDirective.ts b/frontend/src/app/components/checkin/check-in-form-metric/MetricCheckInDirective.ts index ab51ae79a5..f25f36e680 100644 --- a/frontend/src/app/components/checkin/check-in-form-metric/MetricCheckInDirective.ts +++ b/frontend/src/app/components/checkin/check-in-form-metric/MetricCheckInDirective.ts @@ -1,4 +1,4 @@ -import { Directive, HostListener, forwardRef } from '@angular/core'; +import { Directive, HostListener, forwardRef, ElementRef, Renderer2 } from '@angular/core'; import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; @Directive({ @@ -15,6 +15,11 @@ export class MetricCheckInDirective implements ControlValueAccessor { private onChange: (value: number | null) => void = () => {}; protected readonly CHAR_REGEX = /[^0-9.]/g; + constructor( + private el: ElementRef, + private renderer: Renderer2, + ) {} + writeValue(value: any): void { // does not need to be implemented because the display value does not need to be modified } @@ -27,6 +32,10 @@ export class MetricCheckInDirective implements ControlValueAccessor { // does not need to be implemented } + setDisabledState(isDisabled: boolean) { + this.renderer.setProperty(this.el.nativeElement, 'disabled', isDisabled); + } + @HostListener('input', ['$event.target.value']) handleInput(param: string): void { const value: string = param || '0';