From 30b74c668c01bae757cd32a7a08386f76530dd6c Mon Sep 17 00:00:00 2001 From: manasa Date: Sun, 20 Aug 2023 13:02:39 +0530 Subject: [PATCH] updated decimal field component --- .../field/decimal/decimal.component.html | 5 ++-- .../field/decimal/decimal.component.ts | 21 ++++++++------- .../thousand-seperator.directive.ts | 27 +++++++++++++++++++ 3 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 packages/angular-sdk-components/src/app/_directives/thousand-seperator.directive.ts diff --git a/packages/angular-sdk-components/src/app/_components/field/decimal/decimal.component.html b/packages/angular-sdk-components/src/app/_components/field/decimal/decimal.component.html index be3f5022..809ddaff 100644 --- a/packages/angular-sdk-components/src/app/_components/field/decimal/decimal.component.html +++ b/packages/angular-sdk-components/src/app/_components/field/decimal/decimal.component.html @@ -7,10 +7,11 @@ {{ label$ }} ComponentMapperComponent)] + imports: [CommonModule, ReactiveFormsModule, FormsModule, MatFormFieldModule, ThousandSeparatorDirective, MatInputModule, forwardRef(() => ComponentMapperComponent)], }) export class DecimalComponent implements OnInit { @Input() pConn$: any; @@ -135,16 +136,18 @@ export class DecimalComponent implements OnInit { this.componentReference = this.pConn$.getStateProps().value; } - fieldOnChange(event: any) { - // this.angularPConnect.changeHandler( this, event ); - this.angularPConnectData.actions.onChange(this, event); - } + fieldOnChange(event: any) {} fieldOnClick(event: any) {} fieldOnBlur(event: any) { - // PConnect wants to use eventHandler for onBlur - this.angularPConnectData.actions.onBlur(this, event); + console.log('blur', event); + const actionsApi = this.pConn$?.getActionsApi(); + const propName = this.pConn$?.getStateProps().value; + let value = event?.target?.value; + value = value.replace(/,/g, ''); + value !== '' ? Number(value) : value + handleEvent(actionsApi, 'changeNblur', propName, value); } getErrorMessage() { diff --git a/packages/angular-sdk-components/src/app/_directives/thousand-seperator.directive.ts b/packages/angular-sdk-components/src/app/_directives/thousand-seperator.directive.ts new file mode 100644 index 00000000..373c6341 --- /dev/null +++ b/packages/angular-sdk-components/src/app/_directives/thousand-seperator.directive.ts @@ -0,0 +1,27 @@ + + +import { Directive, ElementRef, HostListener } from '@angular/core'; + +@Directive({ + selector: '[appThousandSeparator]', + standalone: true +}) +export class ThousandSeparatorDirective { + + constructor(private el: ElementRef) { } + + @HostListener('input', ['$event']) + onInput(event) { + console.log('event _onHostListenerInput', event); + const input = this.el.nativeElement as HTMLInputElement; + let value: any = input.value.replace(/,/g, ''); // Remove existing commas + if (event?.data !== '.') { + value = Number(value).toLocaleString(); // Add thousands separator + input.value = value; + } + + } +} + + +